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; | 24 typedef std::map<std::string, std::string> SettingsMap; |
25 | 25 |
26 // Minimum periodic checkin interval in seconds. | 26 // Minimum periodic checkin interval in seconds. |
27 static const base::TimeDelta MinimumCheckinInterval(); | 27 static const base::TimeDelta MinimumCheckinInterval(); |
28 | 28 |
29 // Default checkin URL. | |
30 static const GURL DefaultCheckinURL(); | |
31 | |
32 // Calculates digest of provided settings. | 29 // Calculates digest of provided settings. |
33 static std::string CalculateDigest(const SettingsMap& settings); | 30 static std::string CalculateDigest(const SettingsMap& settings); |
34 | 31 |
35 GServicesSettings(); | 32 GServicesSettings(); |
36 ~GServicesSettings(); | 33 ~GServicesSettings(); |
37 | 34 |
38 // Updates the settings based on |checkin_response|. | 35 // Updates the settings based on |checkin_response|. |
39 bool UpdateFromCheckinResponse( | 36 bool UpdateFromCheckinResponse( |
40 const checkin_proto::AndroidCheckinResponse& checkin_response); | 37 const checkin_proto::AndroidCheckinResponse& checkin_response); |
41 | 38 |
42 // Updates the settings based on |load_result|. Returns true if update was | 39 // Updates the settings based on |load_result|. Returns true if update was |
43 // successful, false otherwise. | 40 // successful, false otherwise. |
44 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); | 41 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); |
45 | 42 |
46 SettingsMap settings_map() const { return settings_; } | 43 SettingsMap settings_map() const { return settings_; } |
47 | 44 |
48 std::string digest() const { return digest_; } | 45 std::string digest() const { return digest_; } |
49 | 46 |
50 // Gets the interval at which device should perform a checkin. | 47 // Gets the interval at which device should perform a checkin. |
51 base::TimeDelta GetCheckinInterval() const; | 48 base::TimeDelta GetCheckinInterval() const; |
52 | 49 |
53 // Gets the URL to use when checking in. | 50 // Gets the URL to use when checking in. |
54 GURL GetCheckinURL() const; | 51 GURL GetCheckinURL() const; |
55 | 52 |
56 // Gets address of main MCS endpoint. | 53 // Gets address of main MCS endpoint. |
57 GURL GetMCSMainEndpoint() const; | 54 GURL GetMCSMainEndpoint() const; |
58 | 55 |
59 // Gets address of fallback MCS endpoint. | 56 // Gets address of fallback MCS endpoint. Will be empty if there isn't one. |
60 GURL GetMCSFallbackEndpoint() const; | 57 GURL GetMCSFallbackEndpoint() const; |
61 | 58 |
62 // Gets the URL to use when registering or unregistering the apps. | 59 // Gets the URL to use when registering or unregistering the apps. |
63 GURL GetRegistrationURL() const; | 60 GURL GetRegistrationURL() const; |
64 | 61 |
65 private: | 62 private: |
66 // Digest (hash) of the settings, used to check whether settings need update. | 63 // Digest (hash) of the settings, used to check whether settings need update. |
67 // It is meant to be sent with checkin request, instead of sending the whole | 64 // It is meant to be sent with checkin request, instead of sending the whole |
68 // settings table. | 65 // settings table. |
69 std::string digest_; | 66 std::string digest_; |
70 | 67 |
71 // G-services settings as provided by checkin response. | 68 // G-services settings as provided by checkin response. |
72 SettingsMap settings_; | 69 SettingsMap settings_; |
73 | 70 |
74 // Factory for creating references in callbacks. | 71 // Factory for creating references in callbacks. |
75 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; | 72 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; |
76 | 73 |
77 DISALLOW_COPY_AND_ASSIGN(GServicesSettings); | 74 DISALLOW_COPY_AND_ASSIGN(GServicesSettings); |
78 }; | 75 }; |
79 | 76 |
80 } // namespace gcm | 77 } // namespace gcm |
81 | 78 |
82 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ | 79 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ |
OLD | NEW |