OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import "ios/chrome/browser/updatable_config/updatable_config_base.h" | 5 #import "ios/chrome/browser/updatable_config/updatable_config_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/bind_objc_block.h" | 8 #import "base/mac/bind_objc_block.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 : owner_(owner), descriptor_(descriptor) {} | 56 : owner_(owner), descriptor_(descriptor) {} |
57 | 57 |
58 // Starts fetching |url| for updated configuration. | 58 // Starts fetching |url| for updated configuration. |
59 void Fetch(const GURL& url, net::URLRequestContextGetter* context) { | 59 void Fetch(const GURL& url, net::URLRequestContextGetter* context) { |
60 fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); | 60 fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); |
61 fetcher_->SetRequestContext(context); | 61 fetcher_->SetRequestContext(context); |
62 fetcher_->Start(); | 62 fetcher_->Start(); |
63 } | 63 } |
64 | 64 |
65 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { | 65 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { |
66 DCHECK_EQ(fetcher_, fetcher); | 66 DCHECK_EQ(fetcher_.get(), fetcher); |
67 NSData* responseData = nil; | 67 NSData* responseData = nil; |
68 if (fetcher_->GetResponseCode() == net::HTTP_OK) { | 68 if (fetcher_->GetResponseCode() == net::HTTP_OK) { |
69 std::string response; | 69 std::string response; |
70 fetcher_->GetResponseAsString(&response); | 70 fetcher_->GetResponseAsString(&response); |
71 responseData = | 71 responseData = |
72 [NSData dataWithBytes:response.c_str() length:response.length()]; | 72 [NSData dataWithBytes:response.c_str() length:response.length()]; |
73 } | 73 } |
74 fetcher_.reset(); | 74 fetcher_.reset(); |
75 // If data was fetched, write the fetched data to local store in a | 75 // If data was fetched, write the fetched data to local store in a |
76 // separate thread. Then update the resource descriptor that configuration | 76 // separate thread. Then update the resource descriptor that configuration |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return; | 260 return; |
261 if (!_configFetcher) { | 261 if (!_configFetcher) { |
262 _configFetcher.reset( | 262 _configFetcher.reset( |
263 new ConfigFetcher(self, [_updatableResource descriptor])); | 263 new ConfigFetcher(self, [_updatableResource descriptor])); |
264 } | 264 } |
265 GURL url = net::GURLWithNSURL([[_updatableResource descriptor] updateURL]); | 265 GURL url = net::GURLWithNSURL([[_updatableResource descriptor] updateURL]); |
266 _configFetcher->Fetch(url, _requestContextGetter.get()); | 266 _configFetcher->Fetch(url, _requestContextGetter.get()); |
267 } | 267 } |
268 | 268 |
269 @end | 269 @end |
OLD | NEW |