1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
#define GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
#include <map>
#include <string>
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "google_apis/gcm/base/gcm_export.h"
#include "google_apis/gcm/engine/gcm_store.h"
#include "google_apis/gcm/protocol/checkin.pb.h"
#include "url/gurl.h"
namespace gcm {
// Class responsible for handling G-services settings. It takes care of
// extracting them from checkin response and storing in GCMStore.
class GCM_EXPORT GServicesSettings {
public:
typedef std::map<std::string, std::string> SettingsMap;
// Minimum periodic checkin interval in seconds.
static const base::TimeDelta MinimumCheckinInterval();
// Calculates digest of provided settings.
static std::string CalculateDigest(const SettingsMap& settings);
GServicesSettings();
GServicesSettings(const GServicesSettings&) = delete;
GServicesSettings& operator=(const GServicesSettings&) = delete;
~GServicesSettings();
// Updates the settings based on |checkin_response|.
bool UpdateFromCheckinResponse(
const checkin_proto::AndroidCheckinResponse& checkin_response);
// Updates the settings based on |load_result|. Returns true if update was
// successful, false otherwise.
void UpdateFromLoadResult(const GCMStore::LoadResult& load_result);
SettingsMap settings_map() const { return settings_; }
std::string digest() const { return digest_; }
// Gets the interval at which device should perform a checkin.
base::TimeDelta GetCheckinInterval() const;
// Gets the URL to use when checking in.
GURL GetCheckinURL() const;
// Gets address of main MCS endpoint.
GURL GetMCSMainEndpoint() const;
// Gets address of fallback MCS endpoint. Will be empty if there isn't one.
GURL GetMCSFallbackEndpoint() const;
// Gets the URL to use when registering or unregistering the apps.
GURL GetRegistrationURL() const;
private:
// Digest (hash) of the settings, used to check whether settings need update.
// It is meant to be sent with checkin request, instead of sending the whole
// settings table.
std::string digest_;
// G-services settings as provided by checkin response.
SettingsMap settings_;
// Factory for creating references in callbacks.
base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_{this};
};
} // namespace gcm
#endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_
|