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_SERVICES_GCM_PUSH_MESSAGING_APPLICATION_ID_H_
6 #define CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_APPLICATION_ID_H_
11 #include "base/basictypes.h"
16 namespace user_prefs
{
17 class PrefRegistrySyncable
;
22 // The prefix used for all push messaging application ids.
23 extern const char kPushMessagingApplicationIdPrefix
[];
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
{
30 // Register profile-specific prefs.
31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
33 // Generates a new application id with random app_id_guid.
34 static PushMessagingApplicationId
Generate(
36 int64 service_worker_registration_id
);
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
);
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
,
46 int64 service_worker_registration_id
);
48 // Returns all the PushMessagingApplicationId currently registered for the
50 static std::vector
<PushMessagingApplicationId
> GetAll(Profile
* profile
);
52 ~PushMessagingApplicationId();
54 // Persist this application id to disk.
55 void PersistToDisk(Profile
* profile
) const;
57 // Delete this application id from disk.
58 void DeleteFromDisk(Profile
* profile
) const; // TODO: Does const make sense?
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_
;
69 friend class PushMessagingApplicationIdTest
;
71 // Constructs an invalid app id.
72 PushMessagingApplicationId();
73 // Constructs a valid app id.
74 PushMessagingApplicationId(const std::string
& app_id_guid
,
76 int64 service_worker_registration_id
);
78 std::string app_id_guid_
;
80 int64 service_worker_registration_id_
;
85 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_APPLICATION_ID_H_