| OLD | NEW |
| (Empty) |
| 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 CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_APPLICATION_ID_H_ | |
| 6 #define CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_APPLICATION_ID_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 class Profile; | |
| 15 | |
| 16 namespace user_prefs { | |
| 17 class PrefRegistrySyncable; | |
| 18 } | |
| 19 | |
| 20 namespace gcm { | |
| 21 | |
| 22 // The prefix used for all push messaging application ids. | |
| 23 extern const char kPushMessagingApplicationIdPrefix[]; | |
| 24 | |
| 25 // Type used to identify a web app from a Push API perspective. | |
| 26 // These can be persisted to disk, in a 1:1 mapping between app_id_guid and | |
| 27 // pair<origin, service_worker_registration_id>. | |
| 28 class PushMessagingApplicationId { | |
| 29 public: | |
| 30 // Register profile-specific prefs. | |
| 31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 32 | |
| 33 // Generates a new application id with random app_id_guid. | |
| 34 static PushMessagingApplicationId Generate( | |
| 35 const GURL& origin, | |
| 36 int64 service_worker_registration_id); | |
| 37 | |
| 38 // Looks up an application id by app_id_guid. Will be invalid if not found. | |
| 39 static PushMessagingApplicationId Get(Profile* profile, | |
| 40 const std::string& app_id_guid); | |
| 41 | |
| 42 // Looks up an application id by origin & service worker registration id. | |
| 43 // Will be invalid if not found. | |
| 44 static PushMessagingApplicationId Get(Profile* profile, | |
| 45 const GURL& origin, | |
| 46 int64 service_worker_registration_id); | |
| 47 | |
| 48 // Returns all the PushMessagingApplicationId currently registered for the | |
| 49 // given |profile|. | |
| 50 static std::vector<PushMessagingApplicationId> GetAll(Profile* profile); | |
| 51 | |
| 52 ~PushMessagingApplicationId(); | |
| 53 | |
| 54 // Persist this application id to disk. | |
| 55 void PersistToDisk(Profile* profile) const; | |
| 56 | |
| 57 // Delete this application id from disk. | |
| 58 void DeleteFromDisk(Profile* profile) const; // TODO: Does const make sense? | |
| 59 | |
| 60 bool IsValid() const; | |
| 61 | |
| 62 const std::string& app_id_guid() const { return app_id_guid_; } | |
| 63 const GURL& origin() const { return origin_; } | |
| 64 int64 service_worker_registration_id() const { | |
| 65 return service_worker_registration_id_; | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 friend class PushMessagingApplicationIdTest; | |
| 70 | |
| 71 // Constructs an invalid app id. | |
| 72 PushMessagingApplicationId(); | |
| 73 // Constructs a valid app id. | |
| 74 PushMessagingApplicationId(const std::string& app_id_guid, | |
| 75 const GURL& origin, | |
| 76 int64 service_worker_registration_id); | |
| 77 | |
| 78 std::string app_id_guid_; | |
| 79 GURL origin_; | |
| 80 int64 service_worker_registration_id_; | |
| 81 }; | |
| 82 | |
| 83 } // namespace gcm | |
| 84 | |
| 85 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_APPLICATION_ID_H_ | |
| OLD | NEW |