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.
5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APPLICATION_ID_H_
6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APPLICATION_ID_H_
11 #include "base/basictypes.h"
16 namespace user_prefs
{
17 class PrefRegistrySyncable
;
20 // The prefix used for all push messaging application ids.
21 extern const char kPushMessagingApplicationIdPrefix
[];
23 // Type used to identify a web app from a Push API perspective.
24 // These can be persisted to disk, in a 1:1 mapping between app_id_guid and
25 // pair<origin, service_worker_registration_id>.
26 class PushMessagingApplicationId
{
28 // Register profile-specific prefs.
29 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
31 // Generates a new application id with random app_id_guid.
32 static PushMessagingApplicationId
Generate(
34 int64 service_worker_registration_id
);
36 // Looks up an application id by app_id_guid. Will be invalid if not found.
37 static PushMessagingApplicationId
Get(Profile
* profile
,
38 const std::string
& app_id_guid
);
40 // Looks up an application id by origin & service worker registration id.
41 // Will be invalid if not found.
42 static PushMessagingApplicationId
Get(Profile
* profile
,
44 int64 service_worker_registration_id
);
46 // Returns all the PushMessagingApplicationId currently registered for the
48 static std::vector
<PushMessagingApplicationId
> GetAll(Profile
* profile
);
50 ~PushMessagingApplicationId();
52 // Persist this application id to disk.
53 void PersistToDisk(Profile
* profile
) const;
55 // Delete this application id from disk.
56 void DeleteFromDisk(Profile
* profile
) const; // TODO: Does const make sense?
60 const std::string
& app_id_guid() const { return app_id_guid_
; }
61 const GURL
& origin() const { return origin_
; }
62 int64
service_worker_registration_id() const {
63 return service_worker_registration_id_
;
67 friend class PushMessagingApplicationIdTest
;
69 // Constructs an invalid app id.
70 PushMessagingApplicationId();
71 // Constructs a valid app id.
72 PushMessagingApplicationId(const std::string
& app_id_guid
,
74 int64 service_worker_registration_id
);
76 std::string app_id_guid_
;
78 int64 service_worker_registration_id_
;
81 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_APPLICATION_ID_H_