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

Side by Side Diff: ios/chrome/app/startup/ios_chrome_main.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
OLDNEW
(Empty)
1 // Copyright 2012 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 #include "ios/chrome/app/startup/ios_chrome_main.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include <vector>
10
11 #include "base/logging.h"
12 #include "base/strings/sys_string_conversions.h"
13 #include "base/time/time.h"
14 #include "ios/web/public/app/web_main_runner.h"
15
16 namespace {
17 base::Time* g_start_time;
18 } // namespace
19
20 IOSChromeMain::IOSChromeMain() {
21 web_main_runner_.reset(web::WebMainRunner::Create());
22
23 web::WebMainParams main_params = web::WebMainParams(&main_delegate_);
24 // Copy NSProcessInfo arguments into WebMainParams in debug only, since
25 // command line should be meaningless outside of developer builds.
26 #if !defined(NDEBUG)
27 NSArray* arguments = [[NSProcessInfo processInfo] arguments];
28 main_params.argc = [arguments count];
29 const char* argv[main_params.argc];
30 std::vector<std::string> argv_store;
31
32 // Avoid using std::vector::push_back (or any other method that could cause
33 // the vector to grow) as this will cause the std::string to be copied or
34 // moved (depends on the C++ implementation) which may invalidates the pointer
35 // returned by std::string::c_str(). Even if the strings are moved, this may
36 // cause garbage if std::string uses optimisation for small strings (by
37 // returning pointer to the object internals in that case).
38 argv_store.resize([arguments count]);
39 for (NSUInteger i = 0; i < [arguments count]; i++) {
40 argv_store[i] = base::SysNSStringToUTF8([arguments objectAtIndex:i]);
41 argv[i] = argv_store[i].c_str();
42 }
43 main_params.argv = argv;
44 #endif
45
46 // Chrome registers an AtExitManager in main in order to initialize breakpad
47 // early, so prevent a second registration by WebMainRunner.
48 main_params.register_exit_manager = false;
49 web_main_runner_->Initialize(main_params);
50 }
51
52 IOSChromeMain::~IOSChromeMain() {
53 web_main_runner_->ShutDown();
54 }
55
56 // static
57 void IOSChromeMain::InitStartTime() {
58 DCHECK(!g_start_time);
59 g_start_time = new base::Time(base::Time::Now());
60 }
61
62 // static
63 const base::Time& IOSChromeMain::StartTime() {
64 CHECK(g_start_time);
65 return *g_start_time;
66 }
OLDNEW
« no previous file with comments | « ios/chrome/app/startup/ios_chrome_main.h ('k') | ios/chrome/app/startup/ios_chrome_main_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698