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

Side by Side Diff: ios/chrome/app/steps/launch_to_background.mm

Issue 2580363002: Upstream Chrome on iOS source code [1/11]. (Closed)
Patch Set: Created 4 years 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/app/steps/launch_to_background.h ('k') | ios/chrome/app/steps/launch_to_basic.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // ====== New Architecture =====
6 // = This code is only used in the new iOS Chrome architecture. =
7 // ============================================================================
8
9 #import "ios/chrome/app/steps/launch_to_background.h"
10
11 #include <memory>
12
13 #include "base/mac/bundle_locations.h"
14 #include "base/mac/foundation_util.h"
15 #include "base/memory/ptr_util.h"
16 #include "base/strings/sys_string_conversions.h"
17 #include "base/supports_user_data.h"
18 #include "ios/chrome/app/application_state.h"
19 #include "ios/chrome/app/startup/ios_chrome_main.h"
20 #include "ios/chrome/app/startup/register_experimental_settings.h"
21 #include "ios/chrome/browser/application_context.h"
22 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
23 #include "ios/chrome/browser/web/chrome_web_client.h"
24 #include "ios/web/public/web_client.h"
25
26 #if !defined(__has_feature) || !__has_feature(objc_arc)
27 #error "This file requires ARC support."
28 #endif
29
30 // Step that removes a previously-stored IOSChromeMain instance.
31 @interface StopChromeMain : NSObject<ApplicationStep>
32 @end
33
34 namespace {
35
36 // A SupportsUserData::Data struct to store an IOSChromeMain object and preserve
37 // its lifetime (by storing it in an ApplicationState's |state| property) beyond
38 // the running time of the -StartChromeMain step.
39 class ChromeMainContainer : public base::SupportsUserData::Data {
40 public:
41 explicit ChromeMainContainer(std::unique_ptr<IOSChromeMain> chrome_main)
42 : main_(std::move(chrome_main)) {}
43
44 private:
45 std::unique_ptr<IOSChromeMain> main_;
46 };
47
48 // Key for storing the ChromeMainContainer.
49 const char kChromeMainKey[] = "chrome_main";
50
51 } // namespace
52
53 @implementation SetupBundleAndUserDefaults
54
55 - (BOOL)canRunInState:(ApplicationState*)state {
56 return state.phase == APPLICATION_BASIC;
57 }
58
59 - (void)runInState:(ApplicationState*)state {
60 NSBundle* baseBundle = base::mac::OuterBundle();
61 base::mac::SetBaseBundleID(
62 base::SysNSStringToUTF8([baseBundle bundleIdentifier]).c_str());
63
64 [RegisterExperimentalSettings
65 registerExperimentalSettingsWithUserDefaults:[NSUserDefaults
66 standardUserDefaults]
67 bundle:base::mac::
68 FrameworkBundle()];
69 }
70
71 @end
72
73 @implementation StartChromeMain
74
75 - (BOOL)canRunInState:(ApplicationState*)state {
76 return state.phase == APPLICATION_BASIC;
77 }
78
79 - (void)runInState:(ApplicationState*)state {
80 web::SetWebClient(new ChromeWebClient());
81
82 // Create and persist an IOSChromeMain instance.
83 state.persistentState->SetUserData(
84 kChromeMainKey,
85 new ChromeMainContainer(base::MakeUnique<IOSChromeMain>()));
86
87 // Add a step to the termination steps of |state| that will stop and remove
88 // the IOSChromeMain instance.
89 [[state terminationSteps] addObject:[[StopChromeMain alloc] init]];
90
91 state.phase = APPLICATION_BACKGROUNDED;
92 }
93
94 @end
95
96 @implementation StopChromeMain
97
98 - (BOOL)canRunInState:(ApplicationState*)state {
99 return state.phase == APPLICATION_TERMINATING;
100 }
101
102 - (void)runInState:(ApplicationState*)state {
103 // This should be the last step executed while the app is terminating.
104 if (state.terminationSteps.count) {
105 // There are other steps waiting to run, so add this to the end and return.
106 [state.terminationSteps addObject:self];
107 return;
108 }
109 state.persistentState->RemoveUserData(kChromeMainKey);
110 }
111
112 @end
113
114 @implementation SetBrowserState
115
116 - (BOOL)canRunInState:(ApplicationState*)state {
117 ApplicationContext* applicationContext = GetApplicationContext();
118 if (!applicationContext)
119 return NO;
120
121 return applicationContext->GetChromeBrowserStateManager() &&
122 state.phase == APPLICATION_BACKGROUNDED;
123 }
124
125 - (void)runInState:(ApplicationState*)state {
126 state.browserState = GetApplicationContext()
127 ->GetChromeBrowserStateManager()
128 ->GetLastUsedBrowserState();
129 }
130
131 @end
OLDNEW
« no previous file with comments | « ios/chrome/app/steps/launch_to_background.h ('k') | ios/chrome/app/steps/launch_to_basic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698