OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "sync/internal_api/public/http_bridge.h" | 5 #include "sync/internal_api/public/http_bridge.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return context_.get(); | 52 return context_.get(); |
53 } | 53 } |
54 | 54 |
55 scoped_refptr<base::SingleThreadTaskRunner> | 55 scoped_refptr<base::SingleThreadTaskRunner> |
56 HttpBridge::RequestContextGetter::GetNetworkTaskRunner() const { | 56 HttpBridge::RequestContextGetter::GetNetworkTaskRunner() const { |
57 return network_task_runner_; | 57 return network_task_runner_; |
58 } | 58 } |
59 | 59 |
60 HttpBridgeFactory::HttpBridgeFactory( | 60 HttpBridgeFactory::HttpBridgeFactory( |
61 net::URLRequestContextGetter* baseline_context_getter, | 61 net::URLRequestContextGetter* baseline_context_getter, |
62 const NetworkTimeUpdateCallback& network_time_update_callback, | 62 const NetworkTimeUpdateCallback& network_time_update_callback) |
63 CancelationSignal* cancelation_signal) | |
64 : baseline_request_context_getter_(baseline_context_getter), | 63 : baseline_request_context_getter_(baseline_context_getter), |
65 network_time_update_callback_(network_time_update_callback), | 64 network_time_update_callback_(network_time_update_callback), |
66 cancelation_signal_(cancelation_signal) { | 65 cancelation_signal_(NULL) { |
67 // Registration should never fail. This should happen on the UI thread during | |
68 // init. It would be impossible for a shutdown to have been requested at this | |
69 // point. | |
70 bool result = cancelation_signal_->TryRegisterHandler(this); | |
71 DCHECK(result); | |
72 } | 66 } |
73 | 67 |
74 HttpBridgeFactory::~HttpBridgeFactory() { | 68 HttpBridgeFactory::~HttpBridgeFactory() { |
75 cancelation_signal_->UnregisterHandler(this); | 69 if (cancelation_signal_ != NULL) |
| 70 cancelation_signal_->UnregisterHandler(this); |
76 } | 71 } |
77 | 72 |
78 void HttpBridgeFactory::Init(const std::string& user_agent) { | 73 void HttpBridgeFactory::Init(const std::string& user_agent) { |
79 base::AutoLock lock(context_getter_lock_); | 74 base::AutoLock lock(context_getter_lock_); |
80 | 75 |
81 if (!baseline_request_context_getter_.get()) { | 76 if (!baseline_request_context_getter_.get()) { |
82 // Uh oh. We've been aborted before we finished initializing. There's no | 77 // Uh oh. We've been aborted before we finished initializing. There's no |
83 // point in initializating further; let's just return right away. | 78 // point in initializating further; let's just return right away. |
84 return; | 79 return; |
85 } | 80 } |
86 | 81 |
87 request_context_getter_ = | 82 request_context_getter_ = |
88 new HttpBridge::RequestContextGetter( | 83 new HttpBridge::RequestContextGetter( |
89 baseline_request_context_getter_, user_agent); | 84 baseline_request_context_getter_, user_agent); |
90 } | 85 } |
91 | 86 |
| 87 void HttpBridgeFactory::RegisterCancelationSignal( |
| 88 CancelationSignal* cancelation_signal) { |
| 89 cancelation_signal_ = cancelation_signal; |
| 90 |
| 91 // Registration should never fail. This should happen on the UI thread during |
| 92 // init. It would be impossible for a shutdown to have been requested at this |
| 93 // point. |
| 94 bool result = cancelation_signal_->TryRegisterHandler(this); |
| 95 DCHECK(result); |
| 96 } |
| 97 |
92 HttpPostProviderInterface* HttpBridgeFactory::Create() { | 98 HttpPostProviderInterface* HttpBridgeFactory::Create() { |
93 base::AutoLock lock(context_getter_lock_); | 99 base::AutoLock lock(context_getter_lock_); |
94 | 100 |
95 // If we've been asked to shut down (something which may happen asynchronously | 101 // If we've been asked to shut down (something which may happen asynchronously |
96 // and at pretty much any time), then we won't have a request_context_getter_. | 102 // and at pretty much any time), then we won't have a request_context_getter_. |
97 // Some external mechanism must ensure that this function is not called after | 103 // Some external mechanism must ensure that this function is not called after |
98 // we've been asked to shut down. | 104 // we've been asked to shut down. |
99 CHECK(request_context_getter_.get()); | 105 CHECK(request_context_getter_.get()); |
100 | 106 |
101 HttpBridge* http = new HttpBridge(request_context_getter_.get(), | 107 HttpBridge* http = new HttpBridge(request_context_getter_.get(), |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 int64 sane_time_ms = 0; | 389 int64 sane_time_ms = 0; |
384 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { | 390 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { |
385 network_time_update_callback_.Run( | 391 network_time_update_callback_.Run( |
386 base::Time::FromJsTime(sane_time_ms), | 392 base::Time::FromJsTime(sane_time_ms), |
387 base::TimeDelta::FromMilliseconds(1), | 393 base::TimeDelta::FromMilliseconds(1), |
388 fetch_state_.end_time - fetch_state_.start_time); | 394 fetch_state_.end_time - fetch_state_.start_time); |
389 } | 395 } |
390 } | 396 } |
391 | 397 |
392 } // namespace syncer | 398 } // namespace syncer |
OLD | NEW |