Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Side by Side Diff: ios/chrome/browser/omaha/omaha_service.mm

Issue 2893523003: [ObjC ARC] Converts ios/chrome/browser/omaha:omaha to ARC. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/omaha/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ios/chrome/browser/omaha/omaha_service.h" 5 #include "ios/chrome/browser/omaha/omaha_service.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
14 #include "base/ios/device_util.h" 14 #include "base/ios/device_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/scoped_nsobject.h"
17 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
18 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
19 #include "base/rand_util.h" 18 #include "base/rand_util.h"
20 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
21 #include "base/strings/sys_string_conversions.h" 20 #include "base/strings/sys_string_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
23 #include "base/sys_info.h" 22 #include "base/sys_info.h"
24 #include "base/time/time.h" 23 #include "base/time/time.h"
25 #include "base/values.h" 24 #include "base/values.h"
26 #include "components/metrics/metrics_pref_names.h" 25 #include "components/metrics/metrics_pref_names.h"
(...skipping 10 matching lines...) Expand all
37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 36 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
38 #include "ios/public/provider/chrome/browser/omaha/omaha_service_provider.h" 37 #include "ios/public/provider/chrome/browser/omaha/omaha_service_provider.h"
39 #include "ios/public/provider/chrome/browser/omaha/omaha_xml_writer.h" 38 #include "ios/public/provider/chrome/browser/omaha/omaha_xml_writer.h"
40 #include "ios/web/public/web_thread.h" 39 #include "ios/web/public/web_thread.h"
41 #include "libxml/xmlwriter.h" 40 #include "libxml/xmlwriter.h"
42 #include "net/base/backoff_entry.h" 41 #include "net/base/backoff_entry.h"
43 #include "net/base/load_flags.h" 42 #include "net/base/load_flags.h"
44 #include "net/url_request/url_fetcher.h" 43 #include "net/url_request/url_fetcher.h"
45 #include "url/gurl.h" 44 #include "url/gurl.h"
46 45
46 #if !defined(__has_feature) || !__has_feature(objc_arc)
47 #error "This file requires ARC support."
48 #endif
49
47 namespace { 50 namespace {
48 // Number of hours to wait between successful requests. 51 // Number of hours to wait between successful requests.
49 const int kHoursBetweenRequests = 5; 52 const int kHoursBetweenRequests = 5;
50 // Minimal time to wait between retry requests. 53 // Minimal time to wait between retry requests.
51 const CFTimeInterval kPostRetryBaseSeconds = 3600; 54 const CFTimeInterval kPostRetryBaseSeconds = 3600;
52 // Maximal time to wait between retry requests. 55 // Maximal time to wait between retry requests.
53 const CFTimeInterval kPostRetryMaxSeconds = 6 * kPostRetryBaseSeconds; 56 const CFTimeInterval kPostRetryMaxSeconds = 6 * kPostRetryBaseSeconds;
54 57
55 // Default last sent application version when none has been sent yet. 58 // Default last sent application version when none has been sent yet.
56 const char kDefaultLastSentVersion[] = "0.0.0.0"; 59 const char kDefaultLastSentVersion[] = "0.0.0.0";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // XML parser for the server response. 123 // XML parser for the server response.
121 @interface ResponseParser : NSObject<NSXMLParserDelegate> { 124 @interface ResponseParser : NSObject<NSXMLParserDelegate> {
122 BOOL hasError_; 125 BOOL hasError_;
123 BOOL responseIsParsed_; 126 BOOL responseIsParsed_;
124 BOOL appIsParsed_; 127 BOOL appIsParsed_;
125 BOOL updateCheckIsParsed_; 128 BOOL updateCheckIsParsed_;
126 BOOL urlIsParsed_; 129 BOOL urlIsParsed_;
127 BOOL manifestIsParsed_; 130 BOOL manifestIsParsed_;
128 BOOL pingIsParsed_; 131 BOOL pingIsParsed_;
129 BOOL eventIsParsed_; 132 BOOL eventIsParsed_;
130 base::scoped_nsobject<NSString> appId_; 133 NSString* appId_;
131 std::unique_ptr<UpgradeRecommendedDetails> updateInformation_; 134 std::unique_ptr<UpgradeRecommendedDetails> updateInformation_;
132 } 135 }
133 136
134 // Initialization method. |appId| is the application id one expects to find in 137 // Initialization method. |appId| is the application id one expects to find in
135 // the response message. 138 // the response message.
136 - (instancetype)initWithAppId:(NSString*)appId; 139 - (instancetype)initWithAppId:(NSString*)appId;
137 140
138 // Returns YES if the message has been correctly parsed. 141 // Returns YES if the message has been correctly parsed.
139 - (BOOL)isCorrect; 142 - (BOOL)isCorrect;
140 143
141 // If an upgrade is possible, returns the details of the notification to send. 144 // If an upgrade is possible, returns the details of the notification to send.
142 // Otherwise, return NULL. 145 // Otherwise, return NULL.
143 - (UpgradeRecommendedDetails*)upgradeRecommendedDetails; 146 - (UpgradeRecommendedDetails*)upgradeRecommendedDetails;
144 147
145 @end 148 @end
146 149
147 @implementation ResponseParser 150 @implementation ResponseParser
148 151
149 - (instancetype)initWithAppId:(NSString*)appId { 152 - (instancetype)initWithAppId:(NSString*)appId {
150 if (self = [super init]) { 153 if (self = [super init]) {
151 appId_.reset([appId retain]); 154 appId_ = appId;
152 } 155 }
153 return self; 156 return self;
154 } 157 }
155 158
156 - (BOOL)isCorrect { 159 - (BOOL)isCorrect {
157 // A response should have either a ping ACK or an event ACK, depending on the 160 // A response should have either a ping ACK or an event ACK, depending on the
158 // contents of the request. 161 // contents of the request.
159 return !hasError_ && (pingIsParsed_ || eventIsParsed_); 162 return !hasError_ && (pingIsParsed_ || eventIsParsed_);
160 } 163 }
161 164
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 if (fetcher->GetResponseCode() != 200) { 592 if (fetcher->GetResponseCode() != 200) {
590 DLOG(WARNING) << "Error contacting the Omaha server"; 593 DLOG(WARNING) << "Error contacting the Omaha server";
591 SendOrScheduleNextPing(); 594 SendOrScheduleNextPing();
592 return; 595 return;
593 } 596 }
594 597
595 std::string response; 598 std::string response;
596 bool result = fetcher->GetResponseAsString(&response); 599 bool result = fetcher->GetResponseAsString(&response);
597 DCHECK(result); 600 DCHECK(result);
598 NSData* xml = [NSData dataWithBytes:response.data() length:response.length()]; 601 NSData* xml = [NSData dataWithBytes:response.data() length:response.length()];
599 base::scoped_nsobject<NSXMLParser> parser( 602 NSXMLParser* parser = [[NSXMLParser alloc] initWithData:xml];
600 [[NSXMLParser alloc] initWithData:xml]);
601 const std::string application_id = ios::GetChromeBrowserProvider() 603 const std::string application_id = ios::GetChromeBrowserProvider()
602 ->GetOmahaServiceProvider() 604 ->GetOmahaServiceProvider()
603 ->GetApplicationID(); 605 ->GetApplicationID();
604 base::scoped_nsobject<ResponseParser> delegate([[ResponseParser alloc] 606 ResponseParser* delegate = [[ResponseParser alloc]
605 initWithAppId:base::SysUTF8ToNSString(application_id)]); 607 initWithAppId:base::SysUTF8ToNSString(application_id)];
606 parser.get().delegate = delegate.get(); 608 parser.delegate = delegate;
607 609
608 if (![parser parse] || ![delegate isCorrect]) { 610 if (![parser parse] || ![delegate isCorrect]) {
609 DLOG(ERROR) << "Unable to parse XML response from Omaha server."; 611 DLOG(ERROR) << "Unable to parse XML response from Omaha server.";
610 SendOrScheduleNextPing(); 612 SendOrScheduleNextPing();
611 return; 613 return;
612 } 614 }
613 // Handle success. 615 // Handle success.
614 number_of_tries_ = 0; 616 number_of_tries_ = 0;
615 // Schedule the next request. If requset that just finished was an install 617 // Schedule the next request. If requset that just finished was an install
616 // notification, send an active ping immediately. 618 // notification, send an active ping immediately.
617 next_tries_time_ = sending_install_event_ 619 next_tries_time_ = sending_install_event_
618 ? base::Time::Now() 620 ? base::Time::Now()
619 : base::Time::Now() + base::TimeDelta::FromHours( 621 : base::Time::Now() + base::TimeDelta::FromHours(
620 kHoursBetweenRequests); 622 kHoursBetweenRequests);
621 current_ping_time_ = next_tries_time_; 623 current_ping_time_ = next_tries_time_;
622 last_sent_time_ = base::Time::Now(); 624 last_sent_time_ = base::Time::Now();
623 last_sent_version_ = base::Version(version_info::GetVersionNumber()); 625 last_sent_version_ = base::Version(version_info::GetVersionNumber());
624 sending_install_event_ = false; 626 sending_install_event_ = false;
625 ClearInstallRetryRequestId(); 627 ClearInstallRetryRequestId();
626 PersistStates(); 628 PersistStates();
627 SendOrScheduleNextPing(); 629 SendOrScheduleNextPing();
628 630
629 // Send notification for updates if needed. 631 // Send notification for updates if needed.
630 UpgradeRecommendedDetails* details = 632 UpgradeRecommendedDetails* details = [delegate upgradeRecommendedDetails];
631 [delegate.get() upgradeRecommendedDetails];
632 if (details) { 633 if (details) {
633 web::WebThread::PostTask( 634 web::WebThread::PostTask(
634 web::WebThread::UI, FROM_HERE, 635 web::WebThread::UI, FROM_HERE,
635 base::Bind(upgrade_recommended_callback_, *details)); 636 base::Bind(upgrade_recommended_callback_, *details));
636 } 637 }
637 } 638 }
638 639
639 void OmahaService::GetDebugInformationOnIOThread( 640 void OmahaService::GetDebugInformationOnIOThread(
640 const base::Callback<void(base::DictionaryValue*)> callback) { 641 const base::Callback<void(base::DictionaryValue*)> callback) {
641 auto result = base::MakeUnique<base::DictionaryValue>(); 642 auto result = base::MakeUnique<base::DictionaryValue>();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 702
702 void OmahaService::ClearPersistentStateForTests() { 703 void OmahaService::ClearPersistentStateForTests() {
703 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 704 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
704 [defaults removeObjectForKey:kNextTriesTimesKey]; 705 [defaults removeObjectForKey:kNextTriesTimesKey];
705 [defaults removeObjectForKey:kCurrentPingKey]; 706 [defaults removeObjectForKey:kCurrentPingKey];
706 [defaults removeObjectForKey:kNumberTriesKey]; 707 [defaults removeObjectForKey:kNumberTriesKey];
707 [defaults removeObjectForKey:kLastSentVersionKey]; 708 [defaults removeObjectForKey:kLastSentVersionKey];
708 [defaults removeObjectForKey:kLastSentTimeKey]; 709 [defaults removeObjectForKey:kLastSentTimeKey];
709 [defaults removeObjectForKey:kRetryRequestIdKey]; 710 [defaults removeObjectForKey:kRetryRequestIdKey];
710 } 711 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/omaha/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698