OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/app/startup_tasks.h" |
| 6 |
| 7 #import <MediaPlayer/MediaPlayer.h> |
| 8 |
| 9 #import "base/ios/weak_nsobject.h" |
| 10 #import "base/mac/bind_objc_block.h" |
| 11 #include "components/bookmarks/browser/startup_task_runner_service.h" |
| 12 #include "components/reading_list/core/reading_list_switches.h" |
| 13 #import "ios/chrome/app/deferred_initialization_runner.h" |
| 14 #include "ios/chrome/app/tests_hook.h" |
| 15 #include "ios/chrome/browser/application_context.h" |
| 16 #include "ios/chrome/browser/bookmarks/startup_task_runner_service_factory.h" |
| 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 18 #include "ios/chrome/browser/ios_chrome_io_thread.h" |
| 19 #import "ios/chrome/browser/omaha/omaha_service.h" |
| 20 #include "ios/chrome/browser/reading_list/reading_list_download_service.h" |
| 21 #include "ios/chrome/browser/reading_list/reading_list_download_service_factory.
h" |
| 22 #import "ios/chrome/browser/ui/main/browser_view_information.h" |
| 23 #import "ios/chrome/browser/upgrade/upgrade_center.h" |
| 24 |
| 25 namespace { |
| 26 // Constants for deferred initilization of the profile start-up task runners. |
| 27 NSString* const kStartProfileStartupTaskRunners = |
| 28 @"StartProfileStartupTaskRunners"; |
| 29 } // namespace |
| 30 |
| 31 @interface StartupTasks () |
| 32 |
| 33 // Performs browser state initialization tasks that don't need to happen |
| 34 // synchronously at startup. |
| 35 - (void)performDeferredInitializationForBrowserState: |
| 36 (ios::ChromeBrowserState*)browserState; |
| 37 // Called when UIApplicationWillResignActiveNotification is received. |
| 38 - (void)applicationWillResignActiveNotification:(NSNotification*)notification; |
| 39 |
| 40 @end |
| 41 |
| 42 @implementation StartupTasks |
| 43 |
| 44 #pragma mark - Public methods. |
| 45 |
| 46 - (void)scheduleDeferredBrowserStateInitialization: |
| 47 (ios::ChromeBrowserState*)browserState { |
| 48 DCHECK(browserState); |
| 49 // Schedule the start of the profile deferred task runners. |
| 50 [[DeferredInitializationRunner sharedInstance] |
| 51 enqueueBlockNamed:kStartProfileStartupTaskRunners |
| 52 block:^{ |
| 53 [self performDeferredInitializationForBrowserState: |
| 54 browserState]; |
| 55 }]; |
| 56 } |
| 57 |
| 58 - (void)initializeOmaha { |
| 59 #if defined(GOOGLE_CHROME_BUILD) |
| 60 if (tests_hook::DisableUpdateService()) |
| 61 return; |
| 62 // Start omaha service. We only do this on official builds. |
| 63 OmahaService::Start( |
| 64 GetApplicationContext() |
| 65 ->GetIOSChromeIOThread() |
| 66 ->system_url_request_context_getter(), |
| 67 base::BindBlock(^(const UpgradeRecommendedDetails& details) { |
| 68 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; |
| 69 })); |
| 70 #endif // defined(GOOGLE_CHROME_BUILD) |
| 71 } |
| 72 |
| 73 - (void)registerForApplicationWillResignActiveNotification { |
| 74 [[NSNotificationCenter defaultCenter] |
| 75 addObserver:self |
| 76 selector:@selector(applicationWillResignActiveNotification:) |
| 77 name:UIApplicationWillResignActiveNotification |
| 78 object:nil]; |
| 79 } |
| 80 |
| 81 #pragma mark - Private methods. |
| 82 |
| 83 - (void)performDeferredInitializationForBrowserState: |
| 84 (ios::ChromeBrowserState*)browserState { |
| 85 ios::StartupTaskRunnerServiceFactory::GetForBrowserState(browserState) |
| 86 ->StartDeferredTaskRunners(); |
| 87 if (reading_list::switches::IsReadingListEnabled()) { |
| 88 ReadingListDownloadServiceFactory::GetForBrowserState(browserState) |
| 89 ->Initialize(); |
| 90 } |
| 91 } |
| 92 |
| 93 - (void)applicationWillResignActiveNotification:(NSNotification*)notification { |
| 94 // If the control center is displaying now-playing information from Chrome, |
| 95 // attempt to clear it so that the URL is no longer shown |
| 96 // (crbug.com/475820). The now-playing information will not be cleared if |
| 97 // it's from a different app. |
| 98 NSDictionary* nowPlayingInfo = |
| 99 [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo]; |
| 100 if (nowPlayingInfo[MPMediaItemPropertyTitle]) { |
| 101 // No need to clear playing info if media is being played but there is no |
| 102 // way to check if video or audio is playing in web view. |
| 103 [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil]; |
| 104 } |
| 105 } |
| 106 |
| 107 @end |
OLD | NEW |