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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 virtual void UpdateCredentials(const std::string& email, | 42 virtual void UpdateCredentials(const std::string& email, |
43 const std::string& token) OVERRIDE; | 43 const std::string& token) OVERRIDE; |
44 | 44 |
45 // URLFetcherDelegate implementation. | 45 // URLFetcherDelegate implementation. |
46 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 46 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
47 | 47 |
48 protected: | 48 protected: |
49 void ResetRegisterBackoffEntryForTest( | 49 void ResetRegisterBackoffEntryForTest( |
50 const net::BackoffEntry::Policy* policy); | 50 const net::BackoffEntry::Policy* policy); |
51 | 51 |
| 52 virtual GURL BuildUrl(const std::string& registration_id); |
| 53 |
52 private: | 54 private: |
| 55 friend class GCMNetworkChannelTest; |
53 void Register(); | 56 void Register(); |
54 void OnRegisterComplete(const std::string& registration_id, | 57 void OnRegisterComplete(const std::string& registration_id, |
55 gcm::GCMClient::Result result); | 58 gcm::GCMClient::Result result); |
56 void RequestAccessToken(); | 59 void RequestAccessToken(); |
57 void OnGetTokenComplete(const GoogleServiceAuthError& error, | 60 void OnGetTokenComplete(const GoogleServiceAuthError& error, |
58 const std::string& token); | 61 const std::string& token); |
59 GURL BuildUrl(); | 62 // Base64 encoding/decoding with URL safe alphabet. |
| 63 // http://tools.ietf.org/html/rfc4648#page-7 |
| 64 static void Base64EncodeURLSafe(const std::string& input, |
| 65 std::string* output); |
| 66 static bool Base64DecodeURLSafe(const std::string& input, |
| 67 std::string* output); |
60 | 68 |
61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 69 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
62 scoped_ptr<GCMNetworkChannelDelegate> delegate_; | 70 scoped_ptr<GCMNetworkChannelDelegate> delegate_; |
63 | 71 |
64 // Message is saved until all conditions are met: there is valid | 72 // Message is saved until all conditions are met: there is valid |
65 // registration_id and access_token. | 73 // registration_id and access_token. |
66 std::string cached_message_; | 74 std::string cached_message_; |
67 | 75 |
68 // Access token is saved because in case of auth failure from server we need | 76 // Access token is saved because in case of auth failure from server we need |
69 // to invalidate it. | 77 // to invalidate it. |
70 std::string access_token_; | 78 std::string access_token_; |
71 | 79 |
72 // GCM registration_id is requested one at startup and never refreshed until | 80 // GCM registration_id is requested one at startup and never refreshed until |
73 // next restart. | 81 // next restart. |
74 std::string registration_id_; | 82 std::string registration_id_; |
75 scoped_ptr<net::BackoffEntry> register_backoff_entry_; | 83 scoped_ptr<net::BackoffEntry> register_backoff_entry_; |
76 | 84 |
77 scoped_ptr<net::URLFetcher> fetcher_; | 85 scoped_ptr<net::URLFetcher> fetcher_; |
78 | 86 |
79 base::WeakPtrFactory<GCMNetworkChannel> weak_factory_; | 87 base::WeakPtrFactory<GCMNetworkChannel> weak_factory_; |
80 | 88 |
81 DISALLOW_COPY_AND_ASSIGN(GCMNetworkChannel); | 89 DISALLOW_COPY_AND_ASSIGN(GCMNetworkChannel); |
82 }; | 90 }; |
83 | 91 |
84 } // namespace syncer | 92 } // namespace syncer |
85 | 93 |
86 #endif // SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ | 94 #endif // SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ |
OLD | NEW |