Home | History | Annotate | Download | only in metrics
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
      6 #define COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback_forward.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "components/metrics/proto/system_profile.pb.h"
     14 
     15 namespace metrics {
     16 
     17 class MetricsLogUploader;
     18 
     19 // An abstraction of operations that depend on the embedder's (e.g. Chrome)
     20 // environment.
     21 class MetricsServiceClient {
     22  public:
     23   virtual ~MetricsServiceClient() {}
     24 
     25   // Register the client id with other services (e.g. crash reporting), called
     26   // when metrics recording gets enabled.
     27   virtual void SetClientID(const std::string& client_id) = 0;
     28 
     29   // Whether there's an "off the record" (aka "Incognito") session active.
     30   virtual bool IsOffTheRecordSessionActive() = 0;
     31 
     32   // Returns the current application locale (e.g. "en-US").
     33   virtual std::string GetApplicationLocale() = 0;
     34 
     35   // Retrieves the brand code string associated with the install, returning
     36   // false if no brand code is available.
     37   virtual bool GetBrand(std::string* brand_code) = 0;
     38 
     39   // Returns the release channel (e.g. stable, beta, etc) of the application.
     40   virtual SystemProfileProto::Channel GetChannel() = 0;
     41 
     42   // Returns the version of the application as a string.
     43   virtual std::string GetVersionString() = 0;
     44 
     45   // Returns the install date of the application, in seconds since the epoch.
     46   virtual int64 GetInstallDate() = 0;
     47 
     48   // Called by the metrics service when a log has been uploaded.
     49   virtual void OnLogUploadComplete() = 0;
     50 
     51   // Starts gathering metrics, calling |done_callback| when initial metrics
     52   // gathering is complete.
     53   virtual void StartGatheringMetrics(const base::Closure& done_callback) = 0;
     54 
     55   // Called prior to a metrics log being closed, allowing the client to collect
     56   // extra histograms that will go in that log. Asynchronous API - the client
     57   // implementation should call |done_callback| when complete.
     58   virtual void CollectFinalMetrics(const base::Closure& done_callback) = 0;
     59 
     60   // Creates a MetricsLogUploader with the specified parameters (see comments on
     61   // MetricsLogUploader for details).
     62   virtual scoped_ptr<MetricsLogUploader> CreateUploader(
     63       const std::string& server_url,
     64       const std::string& mime_type,
     65       const base::Callback<void(int)>& on_upload_complete) = 0;
     66 };
     67 
     68 }  // namespace metrics
     69 
     70 #endif  // COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
     71