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

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: re-add logging include 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" 8 #include "base/logging.h"
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/mac/scoped_block.h" 10 #include "base/mac/scoped_block.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // body of the POST request. 97 // body of the POST request.
98 NSDictionary* jsonBody = 98 NSDictionary* jsonBody =
99 @{ kUrlsKey : @[ @{kUrlKey : [[device_ url] absoluteString]} ] }; 99 @{ kUrlsKey : @[ @{kUrlKey : [[device_ url] absoluteString]} ] };
100 [request_ setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonBody 100 [request_ setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonBody
101 options:0 101 options:0
102 error:NULL]]; 102 error:NULL]];
103 [request_ setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 103 [request_ setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
104 [request_ setValue:base::SysUTF8ToNSString(GetUserAgent()) 104 [request_ setValue:base::SysUTF8ToNSString(GetUserAgent())
105 forHTTPHeaderField:@"User-Agent"]; 105 forHTTPHeaderField:@"User-Agent"];
106 106
107 // Set the Accept-Language header from the locale language code. This may
108 // cause us to fetch metadata for the wrong region in languages such as
109 // Chinese that vary significantly between regions.
110 // TODO(mattreynolds): Use the same Accept-Language string as WKWebView.
111 NSString* acceptLanguage =
112 [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
113 [request_ setValue:acceptLanguage forHTTPHeaderField:@"Acccept-Language"];
114
107 startDate_.reset([[NSDate date] retain]); 115 startDate_.reset([[NSDate date] retain]);
108 // Starts the request. 116 // Starts the request.
109 NSURLSession* session = 117 NSURLSession* session =
110 [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration 118 [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration
111 ephemeralSessionConfiguration] 119 ephemeralSessionConfiguration]
112 delegate:nil 120 delegate:nil
113 delegateQueue:[NSOperationQueue mainQueue]]; 121 delegateQueue:[NSOperationQueue mainQueue]];
114 base::WeakNSObject<PhysicalWebRequest> weakSelf(self); 122 base::WeakNSObject<PhysicalWebRequest> weakSelf(self);
115 SessionCompletionProceduralBlock completionHandler = 123 SessionCompletionProceduralBlock completionHandler =
116 ^(NSData* data, NSURLResponse* response, NSError* error) { 124 ^(NSData* data, NSURLResponse* response, NSError* error) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 transmitPower:[device_ transmitPower] 246 transmitPower:[device_ transmitPower]
239 rssi:[device_ rssi] 247 rssi:[device_ rssi]
240 rank:physical_web::kMaxRank]); 248 rank:physical_web::kMaxRank]);
241 if (block_.get() != nil) { 249 if (block_.get() != nil) {
242 block_.get()(device, nil); 250 block_.get()(device, nil);
243 } 251 }
244 } 252 }
245 } 253 }
246 254
247 @end 255 @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