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

Side by Side Diff: content/browser/background_sync/background_sync_registration.h

Issue 1344843003: [BackgroundSync] Add browser side support for SyncRegistration.done (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ncn_max
Patch Set: Extract some of the changes to new CLs Created 5 years, 3 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
7 7
8 #include <list>
9
10 #include "base/callback.h"
8 #include "base/macros.h" 11 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
10 #include "content/browser/background_sync/background_sync.pb.h" 13 #include "content/browser/background_sync/background_sync.pb.h"
11 #include "content/browser/background_sync/background_sync_registration_options.h " 14 #include "content/browser/background_sync/background_sync_registration_options.h "
12 #include "content/common/background_sync_service.mojom.h" 15 #include "content/common/background_sync_service.mojom.h"
13 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h" 17 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h"
15 18
16 namespace content { 19 namespace content {
17 20
18 class CONTENT_EXPORT BackgroundSyncRegistration { 21 class CONTENT_EXPORT BackgroundSyncRegistration {
19 public: 22 public:
20 using RegistrationId = int64_t; 23 using RegistrationId = int64_t;
24 using StateCallback = base::Callback<void(BackgroundSyncState)>;
25
21 static const RegistrationId kInitialId; 26 static const RegistrationId kInitialId;
22 27
23 BackgroundSyncRegistration() = default; 28 BackgroundSyncRegistration();
24 ~BackgroundSyncRegistration() = default; 29 ~BackgroundSyncRegistration();
25 30
26 bool Equals(const BackgroundSyncRegistration& other) const; 31 bool Equals(const BackgroundSyncRegistration& other) const;
27 bool IsValid() const; 32 bool IsValid() const;
33 void AddDoneCallback(const StateCallback& callback);
34 void RunDoneCallbacks();
28 35
29 const BackgroundSyncRegistrationOptions* options() const { return &options_; } 36 const BackgroundSyncRegistrationOptions* options() const { return &options_; }
30 BackgroundSyncRegistrationOptions* options() { return &options_; } 37 BackgroundSyncRegistrationOptions* options() { return &options_; }
31 38
32 RegistrationId id() const { return id_; } 39 RegistrationId id() const { return id_; }
33 void set_id(RegistrationId id) { id_ = id; } 40 void set_id(RegistrationId id) { id_ = id; }
34 41
35 BackgroundSyncState sync_state() const { return sync_state_; } 42 BackgroundSyncState sync_state() const { return sync_state_; }
36 void set_sync_state(BackgroundSyncState state) { sync_state_ = state; } 43 void set_sync_state(BackgroundSyncState state) { sync_state_ = state; }
37 44
38 private: 45 private:
39 static const RegistrationId kInvalidRegistrationId; 46 static const RegistrationId kInvalidRegistrationId;
40 47
41 BackgroundSyncRegistrationOptions options_; 48 BackgroundSyncRegistrationOptions options_;
42 RegistrationId id_ = kInvalidRegistrationId; 49 RegistrationId id_ = kInvalidRegistrationId;
43 BackgroundSyncState sync_state_ = BACKGROUND_SYNC_STATE_PENDING; 50 BackgroundSyncState sync_state_ = BACKGROUND_SYNC_STATE_PENDING;
44 51
52 std::list<StateCallback> notify_done_callbacks_;
53
45 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistration); 54 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistration);
46 }; 55 };
47 56
48 } // namespace content 57 } // namespace content
49 58
50 namespace mojo { 59 namespace mojo {
51 60
52 template <> 61 template <>
53 struct CONTENT_EXPORT 62 struct CONTENT_EXPORT
54 TypeConverter<scoped_ptr<content::BackgroundSyncRegistration>, 63 TypeConverter<scoped_ptr<content::BackgroundSyncRegistration>,
55 content::SyncRegistrationPtr> { 64 content::SyncRegistrationPtr> {
56 static scoped_ptr<content::BackgroundSyncRegistration> Convert( 65 static scoped_ptr<content::BackgroundSyncRegistration> Convert(
57 const content::SyncRegistrationPtr& input); 66 const content::SyncRegistrationPtr& input);
58 }; 67 };
59 68
60 template <> 69 template <>
61 struct CONTENT_EXPORT TypeConverter<content::SyncRegistrationPtr, 70 struct CONTENT_EXPORT TypeConverter<content::SyncRegistrationPtr,
62 content::BackgroundSyncRegistration> { 71 content::BackgroundSyncRegistration> {
63 static content::SyncRegistrationPtr Convert( 72 static content::SyncRegistrationPtr Convert(
64 const content::BackgroundSyncRegistration& input); 73 const content::BackgroundSyncRegistration& input);
65 }; 74 };
66 75
67 } // namespace 76 } // namespace
68 77
69 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ 78 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698