Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace user_prefs { | 18 namespace user_prefs { |
| 19 class PrefRegistrySyncable; | 19 class PrefRegistrySyncable; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // The prefix used for all push messaging application ids. | 22 // The prefix used for all push messaging application ids. |
| 23 extern const char kPushMessagingAppIdentifierPrefix[]; | 23 extern const char kPushMessagingAppIdentifierPrefix[]; |
| 24 | 24 |
| 25 // Type used to identify a Service Worker registration from a Push API | 25 // Type used to identify a Service Worker registration from a Push API |
| 26 // perspective. These can be persisted to prefs, in a 1:1 mapping between | 26 // perspective. These can be persisted to prefs, in a 1:1 mapping between |
| 27 // app_id and pair<origin, service_worker_registration_id>. | 27 // app_id (which includes origin) and service_worker_registration_id. |
| 28 // Legacy mapped values saved by old versions of Chrome are also supported; | |
| 29 // these don't contain the origin in the app_id, so instead they map from | |
| 30 // app_id to pair<origin, service_worker_registration_id>. | |
| 28 class PushMessagingAppIdentifier { | 31 class PushMessagingAppIdentifier { |
| 29 public: | 32 public: |
| 30 // Register profile-specific prefs. | 33 // Register profile-specific prefs. |
| 31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 34 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 32 | 35 |
| 33 // Generates a new app identifier with random app_id. | 36 // Generates a new app identifier, with partially random app_id. |
| 34 static PushMessagingAppIdentifier Generate( | 37 static PushMessagingAppIdentifier Generate( |
| 35 const GURL& origin, | 38 const GURL& origin, |
| 36 int64_t service_worker_registration_id); | 39 int64_t service_worker_registration_id); |
| 37 | 40 |
| 38 // Looks up an app identifier by app_id. If not found, is_null() will be true. | 41 // Looks up an app identifier by app_id. If not found, is_null() will be true. |
| 39 static PushMessagingAppIdentifier Get(Profile* profile, | 42 static PushMessagingAppIdentifier Get(Profile* profile, |
|
Peter Beverloo
2015/05/13 13:04:14
nit: It's not obvious what ::Get() means when read
johnme
2015/05/13 16:18:09
Done (but FindByServiceWorker).
| |
| 40 const std::string& app_id); | 43 const std::string& app_id); |
| 41 | 44 |
| 42 // Looks up an app identifier by origin & service worker registration id. | 45 // Looks up an app identifier by origin & service worker registration id. |
| 43 // If not found, is_null() will be true. | 46 // If not found, is_null() will be true. |
| 44 static PushMessagingAppIdentifier Get(Profile* profile, | 47 static PushMessagingAppIdentifier Get(Profile* profile, |
| 45 const GURL& origin, | 48 const GURL& origin, |
| 46 int64_t service_worker_registration_id); | 49 int64_t service_worker_registration_id); |
| 47 | 50 |
| 48 // Returns all the PushMessagingAppIdentifiers currently registered for the | 51 // Returns all the PushMessagingAppIdentifiers currently registered for the |
| 49 // given |profile|. | 52 // given |profile|. |
| 50 static std::vector<PushMessagingAppIdentifier> GetAll(Profile* profile); | 53 static std::vector<PushMessagingAppIdentifier> GetAll(Profile* profile); |
| 51 | 54 |
| 52 ~PushMessagingAppIdentifier(); | 55 ~PushMessagingAppIdentifier(); |
| 53 | 56 |
| 54 // Persist this app identifier to prefs. | 57 // Persist this app identifier to prefs. |
| 55 void PersistToPrefs(Profile* profile) const; | 58 void PersistToPrefs(Profile* profile) const; |
| 56 | 59 |
| 57 // Delete this app identifier from prefs. | 60 // Delete this app identifier from prefs. |
| 58 void DeleteFromPrefs(Profile* profile) const; | 61 void DeleteFromPrefs(Profile* profile) const; |
| 59 | 62 |
| 60 // Returns true if this identifier does not represent an app (i.e. this was | 63 // Returns true if this identifier does not represent an app (i.e. this was |
| 61 // returned by a failed call to Get). | 64 // returned by a failed call to Get). |
| 62 bool is_null() const { return service_worker_registration_id_ < 0; } | 65 bool is_null() const { return service_worker_registration_id_ < 0; } |
| 63 | 66 |
| 64 // String that should be passed to push services like GCM to identify a | 67 // String that should be passed to push services like GCM to identify a |
| 65 // particular Service Worker (so we can route incoming messages). Example: | 68 // particular Service Worker (so we can route incoming messages). Example: |
| 66 // wp:9CC55CCE-B8F9-4092-A364-3B0F73A3AB5F | 69 // wp:https://foo.example.com:8443#9CC55CCE-B8F9-4092-A364-3B0F73A3AB5F |
| 70 // Legacy app_ids have no origin, e.g. wp:9CC55CCE-B8F9-4092-A364-3B0F73A3AB5F | |
| 67 const std::string& app_id() const { | 71 const std::string& app_id() const { |
| 68 DCHECK(!is_null()); | 72 DCHECK(!is_null()); |
| 69 return app_id_; | 73 return app_id_; |
| 70 } | 74 } |
| 71 | 75 |
| 72 const GURL& origin() const { | 76 const GURL& origin() const { |
| 73 DCHECK(!is_null()); | 77 DCHECK(!is_null()); |
| 74 return origin_; | 78 return origin_; |
| 75 } | 79 } |
| 76 | 80 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 91 | 95 |
| 92 // Validates that all the fields contain valid values. | 96 // Validates that all the fields contain valid values. |
| 93 void DCheckValid() const; | 97 void DCheckValid() const; |
| 94 | 98 |
| 95 std::string app_id_; | 99 std::string app_id_; |
| 96 GURL origin_; | 100 GURL origin_; |
| 97 int64_t service_worker_registration_id_; | 101 int64_t service_worker_registration_id_; |
| 98 }; | 102 }; |
| 99 | 103 |
| 100 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_ | 104 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APP_IDENTIFIER_H_ |
| OLD | NEW |