| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // Class to fetch config update |url| and also act as the delegate to | 50 // Class to fetch config update |url| and also act as the delegate to |
| 51 // handle callbacks from URLFetcher. | 51 // handle callbacks from URLFetcher. |
| 52 class ConfigFetcher : public net::URLFetcherDelegate { | 52 class ConfigFetcher : public net::URLFetcherDelegate { |
| 53 public: | 53 public: |
| 54 ConfigFetcher(UpdatableConfigBase* owner, | 54 ConfigFetcher(UpdatableConfigBase* owner, |
| 55 id<UpdatableResourceDescriptorBridge> descriptor) | 55 id<UpdatableResourceDescriptorBridge> descriptor) |
| 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_.reset(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_, 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); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 return; | 257 return; |
| 258 if (!_configFetcher) { | 258 if (!_configFetcher) { |
| 259 _configFetcher.reset( | 259 _configFetcher.reset( |
| 260 new ConfigFetcher(self, [_updatableResource descriptor])); | 260 new ConfigFetcher(self, [_updatableResource descriptor])); |
| 261 } | 261 } |
| 262 GURL url = net::GURLWithNSURL([[_updatableResource descriptor] updateURL]); | 262 GURL url = net::GURLWithNSURL([[_updatableResource descriptor] updateURL]); |
| 263 _configFetcher->Fetch(url, _requestContextGetter.get()); | 263 _configFetcher->Fetch(url, _requestContextGetter.get()); |
| 264 } | 264 } |
| 265 | 265 |
| 266 @end | 266 @end |
| OLD | NEW |