Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: google_apis/gcm/engine/gservices_settings.h

Issue 288433002: G-services settings v3 implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding tests for settings diff, addressing CR feedback" Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ 5 #ifndef GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
6 #define GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ 6 #define GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "google_apis/gcm/base/gcm_export.h" 13 #include "google_apis/gcm/base/gcm_export.h"
14 #include "google_apis/gcm/engine/gcm_store.h" 14 #include "google_apis/gcm/engine/gcm_store.h"
15 #include "google_apis/gcm/protocol/checkin.pb.h" 15 #include "google_apis/gcm/protocol/checkin.pb.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace gcm { 18 namespace gcm {
19 19
20 // Class responsible for handling G-services settings. It takes care of 20 // Class responsible for handling G-services settings. It takes care of
21 // extracting them from checkin response and storing in GCMStore. 21 // extracting them from checkin response and storing in GCMStore.
22 class GCM_EXPORT GServicesSettings { 22 class GCM_EXPORT GServicesSettings {
23 public: 23 public:
24 typedef std::map<std::string, std::string> SettingsMap;
25
24 // Minimum periodic checkin interval in seconds. 26 // Minimum periodic checkin interval in seconds.
25 static const base::TimeDelta MinimumCheckinInterval(); 27 static const base::TimeDelta MinimumCheckinInterval();
26 28
27 // Default checkin URL. 29 // Default checkin URL.
28 static const GURL DefaultCheckinURL(); 30 static const GURL DefaultCheckinURL();
29 31
32 // Calculates digest of provided settings.
33 static std::string CalculateDigest(const SettingsMap& settings);
34
30 GServicesSettings(); 35 GServicesSettings();
31 ~GServicesSettings(); 36 ~GServicesSettings();
32 37
33 // Updates the settings based on |checkin_response|. 38 // Updates the settings based on |checkin_response|.
34 bool UpdateFromCheckinResponse( 39 bool UpdateFromCheckinResponse(
35 const checkin_proto::AndroidCheckinResponse& checkin_response); 40 const checkin_proto::AndroidCheckinResponse& checkin_response);
36 41
37 // Updates the settings based on |load_result|. Returns true if update was 42 // Updates the settings based on |load_result|. Returns true if update was
38 // successful, false otherwise. 43 // successful, false otherwise.
39 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); 44 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result);
40 45
41 // Gets the settings as a map of string to string for storing. 46 // Gets the settings as a map of string to string for storing.
42 std::map<std::string, std::string> GetSettingsMap() const; 47 SettingsMap settings_map() const { return settings_; }
43 48
44 std::string digest() const { return digest_; } 49 std::string digest() const { return digest_; }
45 50
46 base::TimeDelta checkin_interval() const { return checkin_interval_; } 51 // Gets the interval at which device should perform a checkin.
52 base::TimeDelta GetCheckinInterval() const;
47 53
48 GURL checkin_url() const { return checkin_url_; } 54 // Gets a URL to use when checkin in.
Nicolas Zea 2014/05/14 23:00:33 nit: checkin in -> checking in
fgorski 2014/05/16 20:48:47 Done.
55 GURL GetCheckinURL() const;
49 56
50 GURL mcs_main_endpoint() const { return mcs_main_endpoint_; } 57 // Gets address of main MCS endpoint.
58 GURL GetMCSMainEndpoint() const;
51 59
52 GURL mcs_fallback_endpoint() const { return mcs_fallback_endpoint_; } 60 // Gets address of fallback MCS endpoint.
61 GURL GetMCSFallbackEndpoint() const;
53 62
54 GURL registration_url() const { return registration_url_; } 63 // Gets a URL to use when registering or unregistering the apps.
Nicolas Zea 2014/05/14 23:00:33 nit: a URL -> the URL
fgorski 2014/05/16 20:48:47 Done.
64 GURL GetRegistrationURL() const;
55 65
56 private: 66 private:
57 // Parses the |settings| to fill in specific fields.
58 // TODO(fgorski): Change to a status variable that can be logged to UMA.
59 bool UpdateSettings(const std::map<std::string, std::string>& settings);
60
61 // Digest (hash) of the settings, used to check whether settings need update. 67 // Digest (hash) of the settings, used to check whether settings need update.
62 // It is meant to be sent with checkin request, instead of sending the whole 68 // It is meant to be sent with checkin request, instead of sending the whole
63 // settings table. 69 // settings table.
64 std::string digest_; 70 std::string digest_;
65 71
66 // Time delta between periodic checkins. 72 // G-services settings as provided by checkin response.
67 base::TimeDelta checkin_interval_; 73 SettingsMap settings_;
68
69 // URL that should be used for checkins.
70 GURL checkin_url_;
71
72 // Main MCS endpoint.
73 GURL mcs_main_endpoint_;
74
75 // Fallback MCS endpoint.
76 GURL mcs_fallback_endpoint_;
77
78 // URL that should be used for regisrations and unregistrations.
79 GURL registration_url_;
80 74
81 // Factory for creating references in callbacks. 75 // Factory for creating references in callbacks.
82 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; 76 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_;
83 77
84 DISALLOW_COPY_AND_ASSIGN(GServicesSettings); 78 DISALLOW_COPY_AND_ASSIGN(GServicesSettings);
85 }; 79 };
86 80
87 } // namespace gcm 81 } // namespace gcm
88 82
89 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ 83 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/gservices_settings.cc » ('j') | google_apis/gcm/engine/gservices_settings.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698