gservices_settings.h revision 010d83a9304c5a91596085d917d248abff47903a
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. 4 5#ifndef GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ 6#define GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ 7 8#include <map> 9#include <string> 10 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" 16#include "url/gurl.h" 17 18namespace gcm { 19 20// Class responsible for handling G-services settings. It takes care of 21// extracting them from checkin response and storing in GCMStore. 22class GCM_EXPORT GServicesSettings { 23 public: 24 // Minimum periodic checkin interval in seconds. 25 static const base::TimeDelta MinimumCheckinInterval(); 26 27 // Default checkin URL. 28 static const GURL DefaultCheckinURL(); 29 30 GServicesSettings(); 31 ~GServicesSettings(); 32 33 // Updates the settings based on |checkin_response|. 34 bool UpdateFromCheckinResponse( 35 const checkin_proto::AndroidCheckinResponse& checkin_response); 36 37 // Updates the settings based on |load_result|. Returns true if update was 38 // successful, false otherwise. 39 void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); 40 41 // Gets the settings as a map of string to string for storing. 42 std::map<std::string, std::string> GetSettingsMap() const; 43 44 std::string digest() const { return digest_; } 45 46 base::TimeDelta checkin_interval() const { return checkin_interval_; } 47 48 GURL checkin_url() const { return checkin_url_; } 49 50 // TODO(fgorski): Consider returning GURL and use it for validation. 51 std::string mcs_hostname() const { return mcs_hostname_; } 52 53 int mcs_secure_port() const { return mcs_secure_port_; } 54 55 GURL registration_url() const { return registration_url_; } 56 57 private: 58 // Parses the |settings| to fill in specific fields. 59 // TODO(fgorski): Change to a status variable that can be logged to UMA. 60 bool UpdateSettings(const std::map<std::string, std::string>& settings); 61 62 // Digest (hash) of the settings, used to check whether settings need update. 63 // It is meant to be sent with checkin request, instead of sending the whole 64 // settings table. 65 std::string digest_; 66 67 // Time delta between periodic checkins. 68 base::TimeDelta checkin_interval_; 69 70 // URL that should be used for checkins. 71 GURL checkin_url_; 72 73 // Hostname of the MCS server. 74 std::string mcs_hostname_; 75 76 // Secure port to connect to on MCS sever. 77 int mcs_secure_port_; 78 79 // URL that should be used for regisrations and unregistrations. 80 GURL registration_url_; 81 82 // Factory for creating references in callbacks. 83 base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; 84 85 DISALLOW_COPY_AND_ASSIGN(GServicesSettings); 86}; 87 88} // namespace gcm 89 90#endif // GOOGLE_APIS_GCM_ENGINE_GSERVICES_SETTINGS_H_ 91