blob: 4a94a4b7c183686ba1e2c831fa1b24f44ed6115d [file] [log] [blame]
// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "server/file_watcher.h"
#include "server/service_publisher.h"
#include "server/http_server.h"
#include <base/basictypes.h>
namespace p2p {
namespace server {
// Monitors files in a directory and publishes them on the LAN.
// Also manages the life-cycle of a HTTP server for including
// publishing the current number of connections to the
// HTTP server.
class PeerUpdateManager {
// Constructs an uninitialized object. The user must call Init()
// before calling any other method.
PeerUpdateManager(FileWatcher* watcher,
ServicePublisher* publisher,
HttpServer* http_server,
MetricsLibraryInterface* metrics_lib);
// Initializes the object.
void Init();
void Publish(const base::FilePath& file);
void Update(const base::FilePath& file);
void Unpublish(const base::FilePath& file);
void OnFileWatcherChanged(const base::FilePath& file,
FileWatcher::EventType event_type);
void OnHttpServerNumConnectionsChanged(int num_connections);
// Sends a metric with the FileCount if that value was changed since the last
// time this method was called.
void UpdateFileCountMetric();
void UpdateHttpServer();
void UpdateNumConnections(int num_connections);
FileWatcher* file_watcher_;
ServicePublisher* publisher_;
HttpServer* http_server_;
MetricsLibraryInterface* metrics_lib_;
int num_connections_;
// A copy of publisher_->files().size() the last time it was reported
// to libmetrics.
int last_num_files_;
} // namespace server
} // namespace p2p