Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/browser/push_messaging/push_messaging_app_identifier.h

Issue 1131303002: Cleanup PushMessagingAppIdentifier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_identifier
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_ 5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_
6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_ 6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_
7 7
8 #include <stdint.h>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "url/gurl.h" 13 #include "url/gurl.h"
13 14
14 class Profile; 15 class Profile;
15 16
16 namespace user_prefs { 17 namespace user_prefs {
17 class PrefRegistrySyncable; 18 class PrefRegistrySyncable;
18 } 19 }
19 20
20 // The prefix used for all push messaging application ids. 21 // The prefix used for all push messaging application ids.
21 extern const char kPushMessagingAppIdentifierPrefix[]; 22 extern const char kPushMessagingAppIdentifierPrefix[];
22 23
23 // Type used to identify a web app from a Push API perspective. 24 // Type used to identify a web app (specifically, a Service Worker registration)
Peter Beverloo 2015/05/11 16:54:08 +1 to the addition, but I would prefer to remove t
johnme 2015/05/12 13:21:50 Done.
24 // These can be persisted to disk, in a 1:1 mapping between app_id and 25 // from a Push API perspective. These can be persisted to disk, in a 1:1 mapping
Peter Beverloo 2015/05/11 16:54:07 "to disk" -> "to prefs" to match the other changes
johnme 2015/05/12 13:21:50 Done.
25 // pair<origin, service_worker_registration_id>. 26 // between app_id and pair<origin, service_worker_registration_id>.
26 class PushMessagingAppIdentifier { 27 class PushMessagingAppIdentifier {
27 public: 28 public:
28 // Register profile-specific prefs. 29 // Register profile-specific prefs.
29 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 30 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
30 31
31 // Generates a new app identifier with random app_id. 32 // Generates a new app identifier with random app_id.
32 static PushMessagingAppIdentifier Generate( 33 static PushMessagingAppIdentifier Generate(
33 const GURL& origin, 34 const GURL& origin,
34 int64 service_worker_registration_id); 35 int64_t service_worker_registration_id);
35 36
36 // Looks up an app identifier by app_id. Will be invalid if not found. 37 // Looks up an app identifier by app_id. Will be null if not found.
Peter Beverloo 2015/05/11 16:54:08 What do you think about changing null -> is_null()
johnme 2015/05/12 13:21:50 Done.
37 static PushMessagingAppIdentifier Get(Profile* profile, 38 static PushMessagingAppIdentifier Get(Profile* profile,
38 const std::string& app_id); 39 const std::string& app_id);
39 40
40 // Looks up an app identifier by origin & service worker registration id. 41 // Looks up an app identifier by origin & service worker registration id.
41 // Will be invalid if not found. 42 // Will be null if not found.
42 static PushMessagingAppIdentifier Get(Profile* profile, 43 static PushMessagingAppIdentifier Get(Profile* profile,
43 const GURL& origin, 44 const GURL& origin,
44 int64 service_worker_registration_id); 45 int64_t service_worker_registration_id);
45 46
46 // Returns all the PushMessagingAppIdentifiers currently registered for the 47 // Returns all the PushMessagingAppIdentifiers currently registered for the
47 // given |profile|. 48 // given |profile|.
48 static std::vector<PushMessagingAppIdentifier> GetAll(Profile* profile); 49 static std::vector<PushMessagingAppIdentifier> GetAll(Profile* profile);
49 50
50 ~PushMessagingAppIdentifier(); 51 ~PushMessagingAppIdentifier();
51 52
52 // Persist this app identifier to disk. 53 // Persist this app identifier to prefs.
53 void PersistToDisk(Profile* profile) const; 54 void PersistToPrefs(Profile* profile) const;
54 55
55 // Delete this app identifier from disk. 56 // Delete this app identifier from prefs.
56 void DeleteFromDisk(Profile* profile) const; // TODO: Does const make sense? 57 void DeleteFromPrefs(Profile* profile) const;
57 58
58 bool IsValid() const; 59 // Returns true if this object has not been initialized.
Peter Beverloo 2015/05/11 16:54:07 The object *will* have been initialized. What abou
johnme 2015/05/12 13:21:50 Done ("Returns true if this identifier does not re
60 bool is_null() const { return service_worker_registration_id_ < 0; }
59 61
62 // Perform a DCHECK that the origin, app_id and service_worker_registration_id
Peter Beverloo 2015/05/11 16:54:08 nit: Make this private (per the changes in PushMes
johnme 2015/05/12 13:21:50 Done.
63 // all contain valid values.
64 void DCheckValid() const;
65
66 // String that should be passed to push services like GCM to identify a
67 // particular Service Worker (so we can route incoming messages). Example:
68 // wp:9CC55CCE-B8F9-4092-A364-3B0F73A3AB5F
60 const std::string& app_id() const { return app_id_; } 69 const std::string& app_id() const { return app_id_; }
70
61 const GURL& origin() const { return origin_; } 71 const GURL& origin() const { return origin_; }
62 int64 service_worker_registration_id() const { 72
73 int64_t service_worker_registration_id() const {
63 return service_worker_registration_id_; 74 return service_worker_registration_id_;
64 } 75 }
65 76
66 private: 77 private:
67 friend class PushMessagingAppIdentifierTest; 78 friend class PushMessagingAppIdentifierTest;
68 79
69 // Constructs an invalid app identifier. 80 // Constructs an invalid app identifier.
70 PushMessagingAppIdentifier(); 81 PushMessagingAppIdentifier();
71 // Constructs a valid app identifier. 82 // Constructs a valid app identifier.
72 PushMessagingAppIdentifier(const std::string& app_id, 83 PushMessagingAppIdentifier(const std::string& app_id,
73 const GURL& origin, 84 const GURL& origin,
74 int64 service_worker_registration_id); 85 int64_t service_worker_registration_id);
75 86
76 std::string app_id_; 87 std::string app_id_;
77 GURL origin_; 88 GURL origin_;
78 int64 service_worker_registration_id_; 89 int64_t service_worker_registration_id_;
79 }; 90 };
80 91
81 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_ 92 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698