OLD | NEW |
---|---|
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; | |
jianli
2014/05/13 21:41:52
nit: empty line
fgorski
2014/05/13 23:53:28
Done.
| |
24 // Minimum periodic checkin interval in seconds. | 25 // Minimum periodic checkin interval in seconds. |
25 static const base::TimeDelta MinimumCheckinInterval(); | 26 static const base::TimeDelta MinimumCheckinInterval(); |
26 | 27 |
27 // Default checkin URL. | 28 // Default checkin URL. |
28 static const GURL DefaultCheckinURL(); | 29 static const GURL DefaultCheckinURL(); |
29 | 30 |
31 // Calculates digest of provided settings. | |
32 static std::string CalculateDigest(const SettingsMap& settings); | |
33 | |
30 GServicesSettings(); | 34 GServicesSettings(); |
31 ~GServicesSettings(); | 35 ~GServicesSettings(); |
32 | 36 |
33 // Updates the settings based on |checkin_response|. | 37 // Updates the settings based on |checkin_response|. |
34 bool UpdateFromCheckinResponse( | 38 bool UpdateFromCheckinResponse( |
35 const checkin_proto::AndroidCheckinResponse& checkin_response); | 39 const checkin_proto::AndroidCheckinResponse& checkin_response); |
36 | 40 |
37 // Updates the settings based on |load_result|. Returns true if update was | 41 // Updates the settings based on |load_result|. Returns true if update was |
38 // successful, false otherwise. | 42 // successful, false otherwise. |
39 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); | 43 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); |
40 | 44 |
41 // Gets the settings as a map of string to string for storing. | 45 // Gets the settings as a map of string to string for storing. |
42 std::map<std::string, std::string> GetSettingsMap() const; | 46 SettingsMap GetSettingsMap() const; |
43 | 47 |
44 std::string digest() const { return digest_; } | 48 std::string digest() const { return digest_; } |
45 | 49 |
46 base::TimeDelta checkin_interval() const { return checkin_interval_; } | 50 // Gets the interval at which device should perform a checkin. |
51 base::TimeDelta checkin_interval() const; | |
jianli
2014/05/13 21:41:52
Since now we provide more complicated implementati
fgorski
2014/05/13 23:53:28
Done. Applied that to all settings, as they all ha
| |
47 | 52 |
48 GURL checkin_url() const { return checkin_url_; } | 53 // Gets a URL to use when checkin in. |
54 GURL checkin_url() const; | |
49 | 55 |
50 GURL mcs_main_endpoint() const { return mcs_main_endpoint_; } | 56 // Gets address of main MCS endpoint. |
57 GURL mcs_main_endpoint() const; | |
51 | 58 |
52 GURL mcs_fallback_endpoint() const { return mcs_fallback_endpoint_; } | 59 // Gets address of fallback MCS endpoint. |
60 GURL mcs_fallback_endpoint() const; | |
53 | 61 |
54 GURL registration_url() const { return registration_url_; } | 62 // Gets a URL to use when registering or unregistering the apps. |
63 GURL registration_url() const; | |
55 | 64 |
56 private: | 65 private: |
57 // Parses the |settings| to fill in specific fields. | 66 // Parses the |settings| to fill in specific fields. |
58 // TODO(fgorski): Change to a status variable that can be logged to UMA. | 67 // TODO(fgorski): Change to a status variable that can be logged to UMA. |
59 bool UpdateSettings(const std::map<std::string, std::string>& settings); | 68 bool UpdateSettings(const SettingsMap& settings); |
69 | |
70 // Functions to verify correctnes of newly proposed settings. | |
71 bool VerifySettings(const SettingsMap& settings) const; | |
72 bool VerifyCheckinInterval(const SettingsMap& settings) const; | |
73 bool VerifyCheckinURL(const SettingsMap& settings) const; | |
74 bool VerifyMCSEndpoint(const SettingsMap& settings) const; | |
75 bool VerifyRegistrationURL(const SettingsMap& settings) const; | |
76 | |
77 // Settings digest verification. | |
78 bool VerifyDigest(const SettingsMap& settings, | |
79 const std::string& expected_digest) const; | |
60 | 80 |
61 // Digest (hash) of the settings, used to check whether settings need update. | 81 // 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 | 82 // It is meant to be sent with checkin request, instead of sending the whole |
63 // settings table. | 83 // settings table. |
64 std::string digest_; | 84 std::string digest_; |
65 | 85 |
66 // Time delta between periodic checkins. | 86 // G-services settings as provided by checkin response. |
67 base::TimeDelta checkin_interval_; | 87 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 | 88 |
81 // Factory for creating references in callbacks. | 89 // Factory for creating references in callbacks. |
82 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; | 90 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; |
83 | 91 |
84 DISALLOW_COPY_AND_ASSIGN(GServicesSettings); | 92 DISALLOW_COPY_AND_ASSIGN(GServicesSettings); |
85 }; | 93 }; |
86 | 94 |
87 } // namespace gcm | 95 } // namespace gcm |
88 | 96 |
89 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ | 97 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ |
OLD | NEW |