OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/app/application_delegate/app_state.h" | 5 #import "ios/chrome/app/application_delegate/app_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/critical_closure.h" | 10 #include "base/critical_closure.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" | 43 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" |
44 #include "ios/web/net/request_tracker_impl.h" | 44 #include "ios/web/net/request_tracker_impl.h" |
45 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
46 | 46 |
47 #if !defined(__has_feature) || !__has_feature(objc_arc) | 47 #if !defined(__has_feature) || !__has_feature(objc_arc) |
48 #error "This file requires ARC support." | 48 #error "This file requires ARC support." |
49 #endif | 49 #endif |
50 | 50 |
51 namespace { | 51 namespace { |
52 // Helper method to post |closure| on the UI thread. | 52 // Helper method to post |closure| on the UI thread. |
53 void PostTaskOnUIThread(base::Closure closure) { | 53 void PostTaskOnUIThread(base::OnceClosure closure) { |
54 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, std::move(closure)); | 54 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, std::move(closure)); |
55 } | 55 } |
56 NSString* const kStartupAttemptReset = @"StartupAttempReset"; | 56 NSString* const kStartupAttemptReset = @"StartupAttempReset"; |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 @interface AppState ()<SafeModeCoordinatorDelegate> { | 59 @interface AppState ()<SafeModeCoordinatorDelegate> { |
60 // Container for startup information. | 60 // Container for startup information. |
61 __weak id<StartupInformation> _startupInformation; | 61 __weak id<StartupInformation> _startupInformation; |
62 // Browser launcher to launch browser in different states. | 62 // Browser launcher to launch browser in different states. |
63 __weak id<BrowserLauncher> _browserLauncher; | 63 __weak id<BrowserLauncher> _browserLauncher; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 // Do not save cookies if it is already in progress. | 209 // Do not save cookies if it is already in progress. |
210 if ([[_browserLauncher browserViewInformation] currentBVC].browserState && | 210 if ([[_browserLauncher browserViewInformation] currentBVC].browserState && |
211 !_savingCookies) { | 211 !_savingCookies) { |
212 // Save cookies to disk. The empty critical closure guarantees that the task | 212 // Save cookies to disk. The empty critical closure guarantees that the task |
213 // will be run before backgrounding. | 213 // will be run before backgrounding. |
214 scoped_refptr<net::URLRequestContextGetter> getter = | 214 scoped_refptr<net::URLRequestContextGetter> getter = |
215 [[_browserLauncher browserViewInformation] currentBVC] | 215 [[_browserLauncher browserViewInformation] currentBVC] |
216 .browserState->GetRequestContext(); | 216 .browserState->GetRequestContext(); |
217 _savingCookies = YES; | 217 _savingCookies = YES; |
218 base::Closure criticalClosure = | 218 base::OnceClosure criticalClosure = |
219 base::MakeCriticalClosure(base::BindBlockArc(^{ | 219 base::MakeCriticalClosure(base::BindBlockArc(^{ |
220 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 220 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
221 _savingCookies = NO; | 221 _savingCookies = NO; |
222 })); | 222 })); |
| 223 base::Closure post_back_to_ui = |
| 224 base::Bind(&PostTaskOnUIThread, base::Passed(&criticalClosure)); |
223 web::WebThread::PostTask( | 225 web::WebThread::PostTask( |
224 web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{ | 226 web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{ |
225 net::CookieStoreIOS* store = static_cast<net::CookieStoreIOS*>( | 227 net::CookieStoreIOS* store = static_cast<net::CookieStoreIOS*>( |
226 getter->GetURLRequestContext()->cookie_store()); | 228 getter->GetURLRequestContext()->cookie_store()); |
227 // FlushStore() runs its callback on any thread. Jump back to UI. | 229 // FlushStore() runs its callback on any thread. Jump back to UI. |
228 store->FlushStore(base::Bind(&PostTaskOnUIThread, criticalClosure)); | 230 store->FlushStore(post_back_to_ui); |
229 })); | 231 })); |
230 } | 232 } |
231 | 233 |
232 // Mark the startup as clean if it hasn't already been. | 234 // Mark the startup as clean if it hasn't already been. |
233 [[DeferredInitializationRunner sharedInstance] | 235 [[DeferredInitializationRunner sharedInstance] |
234 runBlockIfNecessary:kStartupAttemptReset]; | 236 runBlockIfNecessary:kStartupAttemptReset]; |
235 // Set date/time that the background fetch handler was called in the user | 237 // Set date/time that the background fetch handler was called in the user |
236 // defaults. | 238 // defaults. |
237 [MetricsMediator logDateInUserDefaults]; | 239 [MetricsMediator logDateInUserDefaults]; |
238 // Clear the memory warning flag since the app is now safely in background. | 240 // Clear the memory warning flag since the app is now safely in background. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 self = [self initWithBrowserLauncher:browserLauncher | 502 self = [self initWithBrowserLauncher:browserLauncher |
501 startupInformation:startupInformation | 503 startupInformation:startupInformation |
502 applicationDelegate:applicationDelegate]; | 504 applicationDelegate:applicationDelegate]; |
503 if (self) { | 505 if (self) { |
504 _shouldOpenNTPTabOnActive = shouldOpenNTP; | 506 _shouldOpenNTPTabOnActive = shouldOpenNTP; |
505 } | 507 } |
506 return self; | 508 return self; |
507 } | 509 } |
508 | 510 |
509 @end | 511 @end |
OLD | NEW |