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.
5 #ifndef GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
6 #define GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "google_apis/gcm/base/gcm_export.h"
14 #include "google_apis/gcm/engine/gcm_store.h"
15 #include "google_apis/gcm/protocol/checkin.pb.h"
20 // Class responsible for handling G-services settings. It takes care of
21 // extracting them from checkin response and storing in GCMStore.
22 class GCM_EXPORT GServicesSettings
{
24 typedef std::map
<std::string
, std::string
> SettingsMap
;
26 // Minimum periodic checkin interval in seconds.
27 static const base::TimeDelta
MinimumCheckinInterval();
29 // Default checkin URL.
30 static const GURL
DefaultCheckinURL();
32 // Calculates digest of provided settings.
33 static std::string
CalculateDigest(const SettingsMap
& settings
);
38 // Updates the settings based on |checkin_response|.
39 bool UpdateFromCheckinResponse(
40 const checkin_proto::AndroidCheckinResponse
& checkin_response
);
42 // Updates the settings based on |load_result|. Returns true if update was
43 // successful, false otherwise.
44 void UpdateFromLoadResult(const GCMStore::LoadResult
& load_result
);
46 SettingsMap
settings_map() const { return settings_
; }
48 std::string
digest() const { return digest_
; }
50 // Gets the interval at which device should perform a checkin.
51 base::TimeDelta
GetCheckinInterval() const;
53 // Gets the URL to use when checking in.
54 GURL
GetCheckinURL() const;
56 // Gets address of main MCS endpoint.
57 GURL
GetMCSMainEndpoint() const;
59 // Gets address of fallback MCS endpoint.
60 GURL
GetMCSFallbackEndpoint() const;
62 // Gets the URL to use when registering or unregistering the apps.
63 GURL
GetRegistrationURL() const;
66 // 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
71 // G-services settings as provided by checkin response.
72 SettingsMap settings_
;
74 // Factory for creating references in callbacks.
75 base::WeakPtrFactory
<GServicesSettings
> weak_ptr_factory_
;
77 DISALLOW_COPY_AND_ASSIGN(GServicesSettings
);
82 #endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_