[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / invalidation / gcm_invalidation_bridge.h
bloba9d781e478b3dbc5e8919e8ddf5a1a8593a138f9
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_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_
6 #define CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "chrome/browser/services/gcm/gcm_app_handler.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
14 #include "google_apis/gcm/gcm_client.h"
15 #include "sync/notifier/gcm_network_channel_delegate.h"
17 class IdentityProvider;
19 namespace base {
20 class SingleThreadTaskRunner;
21 } // namespace base
23 namespace gcm {
24 class GCMService;
25 } // namespace gcm
27 namespace invalidation {
29 // GCMInvalidationBridge and GCMInvalidationBridge::Core implement functions
30 // needed for GCMNetworkChannel. GCMInvalidationBridge lives on UI thread while
31 // Core lives on IO thread. Core implements GCMNetworkChannelDelegate and posts
32 // all function calls to GCMInvalidationBridge which does actual work to perform
33 // them.
34 class GCMInvalidationBridge : public gcm::GCMAppHandler,
35 public OAuth2TokenService::Consumer,
36 public base::NonThreadSafe {
37 public:
38 class Core;
40 GCMInvalidationBridge(gcm::GCMService* gcm_service,
41 IdentityProvider* identity_provider);
42 virtual ~GCMInvalidationBridge();
44 // OAuth2TokenService::Consumer implementation.
45 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
46 const std::string& access_token,
47 const base::Time& expiration_time) OVERRIDE;
48 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
49 const GoogleServiceAuthError& error) OVERRIDE;
51 // gcm::GCMEventRouter implementation.
52 virtual void ShutdownHandler() OVERRIDE;
53 virtual void OnMessage(const std::string& app_id,
54 const gcm::GCMClient::IncomingMessage& message)
55 OVERRIDE;
56 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
57 virtual void OnSendError(
58 const std::string& app_id,
59 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
61 scoped_ptr<syncer::GCMNetworkChannelDelegate> CreateDelegate();
63 void CoreInitializationDone(
64 base::WeakPtr<Core> core,
65 scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner);
67 // Functions reflecting GCMNetworkChannelDelegate interface. These are called
68 // on UI thread to perform actual work.
69 void RequestToken(
70 syncer::GCMNetworkChannelDelegate::RequestTokenCallback callback);
71 void InvalidateToken(const std::string& token);
73 void Register(syncer::GCMNetworkChannelDelegate::RegisterCallback callback);
75 void SubscribeForIncomingMessages();
77 void RegisterFinished(
78 syncer::GCMNetworkChannelDelegate::RegisterCallback callback,
79 const std::string& registration_id,
80 gcm::GCMClient::Result result);
82 private:
83 gcm::GCMService* const gcm_service_;
84 IdentityProvider* const identity_provider_;
86 base::WeakPtr<Core> core_;
87 scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner_;
89 // Fields related to RequestToken function.
90 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
91 syncer::GCMNetworkChannelDelegate::RequestTokenCallback
92 request_token_callback_;
93 bool subscribed_for_incoming_messages_;
95 base::WeakPtrFactory<GCMInvalidationBridge> weak_factory_;
97 DISALLOW_COPY_AND_ASSIGN(GCMInvalidationBridge);
100 } // namespace invalidation
102 #endif // CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_