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

Side by Side Diff: chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h

Issue 8586014: [Sync] Replace uses of ObserverListThreadSafe with WeakHandles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // An implementation of SyncNotifier that wraps InvalidationNotifier 5 // An implementation of SyncNotifier that wraps InvalidationNotifier
6 // on its own thread. 6 // on its own thread.
7 7
8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ 8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
9 #define CHROME_BROWSER_SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ 9 #define CHROME_BROWSER_SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
10 #pragma once 10 #pragma once
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/observer_list.h"
17 #include "chrome/browser/sync/notifier/invalidation_version_tracker.h" 19 #include "chrome/browser/sync/notifier/invalidation_version_tracker.h"
18 #include "chrome/browser/sync/notifier/sync_notifier.h" 20 #include "chrome/browser/sync/notifier/sync_notifier.h"
21 #include "chrome/browser/sync/notifier/sync_notifier_observer.h"
19 #include "chrome/browser/sync/util/weak_handle.h" 22 #include "chrome/browser/sync/util/weak_handle.h"
20 #include "jingle/notifier/base/notifier_options.h" 23 #include "jingle/notifier/base/notifier_options.h"
21 24
22 namespace base { 25 namespace base {
23 class MessageLoopProxy; 26 class MessageLoopProxy;
24 } 27 }
25 28
26 namespace sync_notifier { 29 namespace sync_notifier {
27 30
28 class NonBlockingInvalidationNotifier : public SyncNotifier { 31 class NonBlockingInvalidationNotifier
32 : public SyncNotifier,
33 public SyncNotifierObserver {
29 public: 34 public:
30 // |invalidation_version_tracker| must be initialized. 35 // |invalidation_version_tracker| must be initialized.
31 NonBlockingInvalidationNotifier( 36 NonBlockingInvalidationNotifier(
32 const notifier::NotifierOptions& notifier_options, 37 const notifier::NotifierOptions& notifier_options,
33 const InvalidationVersionMap& initial_max_invalidation_versions, 38 const InvalidationVersionMap& initial_max_invalidation_versions,
34 const browser_sync::WeakHandle<InvalidationVersionTracker>& 39 const browser_sync::WeakHandle<InvalidationVersionTracker>&
35 invalidation_version_tracker, 40 invalidation_version_tracker,
36 const std::string& client_info); 41 const std::string& client_info);
37 42
38 virtual ~NonBlockingInvalidationNotifier(); 43 virtual ~NonBlockingInvalidationNotifier();
39 44
40 // SyncNotifier implementation. 45 // SyncNotifier implementation.
41 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; 46 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE;
42 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; 47 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE;
43 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; 48 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
44 virtual void SetState(const std::string& state) OVERRIDE; 49 virtual void SetState(const std::string& state) OVERRIDE;
45 virtual void UpdateCredentials( 50 virtual void UpdateCredentials(
46 const std::string& email, const std::string& token) OVERRIDE; 51 const std::string& email, const std::string& token) OVERRIDE;
47 virtual void UpdateEnabledTypes( 52 virtual void UpdateEnabledTypes(
48 const syncable::ModelTypeSet& enabled_types) OVERRIDE; 53 const syncable::ModelTypeSet& enabled_types) OVERRIDE;
49 virtual void SendNotification( 54 virtual void SendNotification(
50 const syncable::ModelTypeSet& changed_types) OVERRIDE; 55 const syncable::ModelTypeSet& changed_types) OVERRIDE;
51 56
57 // SyncNotifierObserver implementation.
58 virtual void OnIncomingNotification(
59 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE;
60 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE;
61 virtual void StoreState(const std::string& state) OVERRIDE;
62
52 private: 63 private:
53 // The real guts of NonBlockingInvalidationNotifier, which allows this class
54 // to not be refcounted.
55 class Core; 64 class Core;
65
66 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_;
67
68 // Our observers (which must live on the parent thread).
69 ObserverList<SyncNotifierObserver> observers_;
70
71 // The real guts of NonBlockingInvalidationNotifier, which allows
72 // this class to live completely on the parent thread.
56 scoped_refptr<Core> core_; 73 scoped_refptr<Core> core_;
57 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; 74 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_;
58 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 75 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
76
59 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); 77 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier);
60 }; 78 };
61 79
62 } // namespace sync_notifier 80 } // namespace sync_notifier
63 81
64 #endif // CHROME_BROWSER_SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ 82 #endif // CHROME_BROWSER_SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698