OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ | 5 #ifndef SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ |
6 #define SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ | 6 #define SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/url_request/url_fetcher_delegate.h" | |
13 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
15 #include "sync/notifier/gcm_network_channel_delegate.h" | |
14 #include "sync/notifier/sync_system_resources.h" | 16 #include "sync/notifier/sync_system_resources.h" |
17 #include "url/gurl.h" | |
18 | |
19 class GoogleServiceAuthError; | |
15 | 20 |
16 namespace syncer { | 21 namespace syncer { |
17 | 22 |
18 // GCMNetworkChannel is an implementation of SyncNetworkChannel that routes | 23 // GCMNetworkChannel is an implementation of SyncNetworkChannel that routes |
19 // messages through GCMProfileService. | 24 // messages through GCMProfileService. |
20 class SYNC_EXPORT_PRIVATE GCMNetworkChannel | 25 class SYNC_EXPORT_PRIVATE GCMNetworkChannel |
rlarocque
2014/01/16 18:52:48
The threading code is starting to get complicated.
pavely
2014/01/17 00:44:39
Actually everything that happens to this class is
| |
21 : public SyncNetworkChannel { | 26 : public SyncNetworkChannel, |
27 public net::URLFetcherDelegate { | |
22 public: | 28 public: |
23 explicit GCMNetworkChannel(); | 29 explicit GCMNetworkChannel( |
30 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | |
31 scoped_ptr<GCMNetworkChannelDelegate> delegate); | |
24 | 32 |
25 virtual ~GCMNetworkChannel(); | 33 virtual ~GCMNetworkChannel(); |
26 | 34 |
27 // SyncNetworkChannel implementation. | 35 // SyncNetworkChannel implementation. |
28 virtual void SendEncodedMessage(const std::string& encoded_message) OVERRIDE; | 36 virtual void SendEncodedMessage(const std::string& encoded_message) OVERRIDE; |
29 virtual void UpdateCredentials(const std::string& email, | 37 virtual void UpdateCredentials(const std::string& email, |
30 const std::string& token) OVERRIDE; | 38 const std::string& token) OVERRIDE; |
31 | 39 |
40 // URLFetcherDelegate implementation. | |
41 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
42 | |
32 private: | 43 private: |
44 void OnRegisterComplete(const std::string& registration_id, | |
45 gcm::GCMClient::Result result); | |
46 void RequestAccessToken(); | |
47 void OnGetTokenComplete(const GoogleServiceAuthError& error, | |
48 const std::string& token); | |
49 GURL BuildUrl(); | |
50 | |
51 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
52 scoped_ptr<GCMNetworkChannelDelegate> delegate_; | |
53 | |
54 // Message is saved until all conditions are met: there is valid | |
55 // registration_id and access_token. | |
56 std::string encoded_message_; | |
57 | |
58 // Access token is saved because in case of auth failure from server we need | |
59 // to invalidate it. | |
60 std::string access_token_; | |
61 | |
62 // GCM registration_id is requested one at startup and never refreshed until | |
63 // next restart. | |
64 std::string registration_id_; | |
65 | |
66 scoped_ptr<net::URLFetcher> fetcher_; | |
67 | |
68 base::WeakPtrFactory<GCMNetworkChannel> weak_factory_; | |
69 | |
33 DISALLOW_COPY_AND_ASSIGN(GCMNetworkChannel); | 70 DISALLOW_COPY_AND_ASSIGN(GCMNetworkChannel); |
34 }; | 71 }; |
35 | 72 |
36 } // namespace syncer | 73 } // namespace syncer |
37 | 74 |
38 #endif // SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ | 75 #endif // SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ |
OLD | NEW |