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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/app/steps/launch_to_background.mm
diff --git a/ios/chrome/app/steps/launch_to_background.mm b/ios/chrome/app/steps/launch_to_background.mm
new file mode 100644
index 0000000000000000000000000000000000000000..9a1fed66b26826d9b96a3a2ff02367ec111d274a
--- /dev/null
+++ b/ios/chrome/app/steps/launch_to_background.mm
@@ -0,0 +1,131 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// ====== New Architecture =====
+// = This code is only used in the new iOS Chrome architecture. =
+// ============================================================================
+
+#import "ios/chrome/app/steps/launch_to_background.h"
+
+#include <memory>
+
+#include "base/mac/bundle_locations.h"
+#include "base/mac/foundation_util.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/supports_user_data.h"
+#include "ios/chrome/app/application_state.h"
+#include "ios/chrome/app/startup/ios_chrome_main.h"
+#include "ios/chrome/app/startup/register_experimental_settings.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
+#include "ios/chrome/browser/web/chrome_web_client.h"
+#include "ios/web/public/web_client.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+// Step that removes a previously-stored IOSChromeMain instance.
+@interface StopChromeMain : NSObject<ApplicationStep>
+@end
+
+namespace {
+
+// A SupportsUserData::Data struct to store an IOSChromeMain object and preserve
+// its lifetime (by storing it in an ApplicationState's |state| property) beyond
+// the running time of the -StartChromeMain step.
+class ChromeMainContainer : public base::SupportsUserData::Data {
+ public:
+ explicit ChromeMainContainer(std::unique_ptr<IOSChromeMain> chrome_main)
+ : main_(std::move(chrome_main)) {}
+
+ private:
+ std::unique_ptr<IOSChromeMain> main_;
+};
+
+// Key for storing the ChromeMainContainer.
+const char kChromeMainKey[] = "chrome_main";
+
+} // namespace
+
+@implementation SetupBundleAndUserDefaults
+
+- (BOOL)canRunInState:(ApplicationState*)state {
+ return state.phase == APPLICATION_BASIC;
+}
+
+- (void)runInState:(ApplicationState*)state {
+ NSBundle* baseBundle = base::mac::OuterBundle();
+ base::mac::SetBaseBundleID(
+ base::SysNSStringToUTF8([baseBundle bundleIdentifier]).c_str());
+
+ [RegisterExperimentalSettings
+ registerExperimentalSettingsWithUserDefaults:[NSUserDefaults
+ standardUserDefaults]
+ bundle:base::mac::
+ FrameworkBundle()];
+}
+
+@end
+
+@implementation StartChromeMain
+
+- (BOOL)canRunInState:(ApplicationState*)state {
+ return state.phase == APPLICATION_BASIC;
+}
+
+- (void)runInState:(ApplicationState*)state {
+ web::SetWebClient(new ChromeWebClient());
+
+ // Create and persist an IOSChromeMain instance.
+ state.persistentState->SetUserData(
+ kChromeMainKey,
+ new ChromeMainContainer(base::MakeUnique<IOSChromeMain>()));
+
+ // Add a step to the termination steps of |state| that will stop and remove
+ // the IOSChromeMain instance.
+ [[state terminationSteps] addObject:[[StopChromeMain alloc] init]];
+
+ state.phase = APPLICATION_BACKGROUNDED;
+}
+
+@end
+
+@implementation StopChromeMain
+
+- (BOOL)canRunInState:(ApplicationState*)state {
+ return state.phase == APPLICATION_TERMINATING;
+}
+
+- (void)runInState:(ApplicationState*)state {
+ // This should be the last step executed while the app is terminating.
+ if (state.terminationSteps.count) {
+ // There are other steps waiting to run, so add this to the end and return.
+ [state.terminationSteps addObject:self];
+ return;
+ }
+ state.persistentState->RemoveUserData(kChromeMainKey);
+}
+
+@end
+
+@implementation SetBrowserState
+
+- (BOOL)canRunInState:(ApplicationState*)state {
+ ApplicationContext* applicationContext = GetApplicationContext();
+ if (!applicationContext)
+ return NO;
+
+ return applicationContext->GetChromeBrowserStateManager() &&
+ state.phase == APPLICATION_BACKGROUNDED;
+}
+
+- (void)runInState:(ApplicationState*)state {
+ state.browserState = GetApplicationContext()
+ ->GetChromeBrowserStateManager()
+ ->GetLastUsedBrowserState();
+}
+
+@end
« 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