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

Side by Side Diff: ios/chrome/common/physical_web/physical_web_request.mm

Issue 2042863002: Set the Accept-Language header in Physical Web requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/common/physical_web/physical_web_request.h" 5 #import "ios/chrome/common/physical_web/physical_web_request.h"
6 6
7 #include "base/ios/weak_nsobject.h" 7 #include "base/ios/weak_nsobject.h"
8 #include "base/logging.h"
9 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
10 #include "base/mac/scoped_block.h" 9 #include "base/mac/scoped_block.h"
11 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
12 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
13 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
14 #include "components/version_info/version_info.h" 13 #include "components/version_info/version_info.h"
15 #include "google_apis/google_api_keys.h" 14 #include "google_apis/google_api_keys.h"
16 #import "ios/chrome/common/physical_web/physical_web_device.h" 15 #import "ios/chrome/common/physical_web/physical_web_device.h"
17 #import "ios/chrome/common/physical_web/physical_web_types.h" 16 #import "ios/chrome/common/physical_web/physical_web_types.h"
18 #include "ios/web/public/user_agent.h" 17 #include "ios/web/public/user_agent.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 61
63 - (instancetype)initWithDevice:(PhysicalWebDevice*)device { 62 - (instancetype)initWithDevice:(PhysicalWebDevice*)device {
64 self = [super init]; 63 self = [super init];
65 if (self) { 64 if (self) {
66 device_.reset([device retain]); 65 device_.reset([device retain]);
67 } 66 }
68 return self; 67 return self;
69 } 68 }
70 69
71 - (instancetype)init { 70 - (instancetype)init {
72 NOTREACHED(); 71 NOTREACHED();
Olivier 2016/06/09 07:47:31 This is defined int base/logging. Please let the i
mattreynolds 2016/06/09 19:43:57 Oops, re-added
73 return nil; 72 return nil;
74 } 73 }
75 74
76 - (void)cancel { 75 - (void)cancel {
77 [urlSessionTask_ cancel]; 76 [urlSessionTask_ cancel];
78 block_.reset(); 77 block_.reset();
79 } 78 }
80 79
81 - (void)start:(physical_web::RequestFinishedBlock)block { 80 - (void)start:(physical_web::RequestFinishedBlock)block {
82 block_.reset([block copy]); 81 block_.reset([block copy]);
(...skipping 14 matching lines...) Expand all
97 // body of the POST request. 96 // body of the POST request.
98 NSDictionary* jsonBody = 97 NSDictionary* jsonBody =
99 @{ kUrlsKey : @[ @{kUrlKey : [[device_ url] absoluteString]} ] }; 98 @{ kUrlsKey : @[ @{kUrlKey : [[device_ url] absoluteString]} ] };
100 [request_ setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonBody 99 [request_ setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonBody
101 options:0 100 options:0
102 error:NULL]]; 101 error:NULL]];
103 [request_ setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 102 [request_ setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
104 [request_ setValue:base::SysUTF8ToNSString(GetUserAgent()) 103 [request_ setValue:base::SysUTF8ToNSString(GetUserAgent())
105 forHTTPHeaderField:@"User-Agent"]; 104 forHTTPHeaderField:@"User-Agent"];
106 105
106 // Set the Accept-Language header from the locale language code. This may
107 // cause us to fetch metadata for the wrong region in languages such as
108 // Chinese that vary significantly between regions.
109 // TODO(mattreynolds): Use the same Accept-Language string as WKWebView.
110 NSString* acceptLanguage =
111 [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
112 [request_ setValue:acceptLanguage forHTTPHeaderField:@"Acccept-Language"];
113
107 startDate_.reset([[NSDate date] retain]); 114 startDate_.reset([[NSDate date] retain]);
108 // Starts the request. 115 // Starts the request.
109 NSURLSession* session = 116 NSURLSession* session =
110 [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration 117 [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration
111 ephemeralSessionConfiguration] 118 ephemeralSessionConfiguration]
112 delegate:nil 119 delegate:nil
113 delegateQueue:[NSOperationQueue mainQueue]]; 120 delegateQueue:[NSOperationQueue mainQueue]];
114 base::WeakNSObject<PhysicalWebRequest> weakSelf(self); 121 base::WeakNSObject<PhysicalWebRequest> weakSelf(self);
115 SessionCompletionProceduralBlock completionHandler = 122 SessionCompletionProceduralBlock completionHandler =
116 ^(NSData* data, NSURLResponse* response, NSError* error) { 123 ^(NSData* data, NSURLResponse* response, NSError* error) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 transmitPower:[device_ transmitPower] 245 transmitPower:[device_ transmitPower]
239 rssi:[device_ rssi] 246 rssi:[device_ rssi]
240 rank:physical_web::kMaxRank]); 247 rank:physical_web::kMaxRank]);
241 if (block_.get() != nil) { 248 if (block_.get() != nil) {
242 block_.get()(device, nil); 249 block_.get()(device, nil);
243 } 250 }
244 } 251 }
245 } 252 }
246 253
247 @end 254 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698