File: gservices_settings.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (81 lines) | stat: -rw-r--r-- 2,597 bytes parent folder | download | duplicates (11)
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_