[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / chrome_process_singleton.cc
1 // Copyright 2013 The Chromium Authors
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 "chrome/browser/chrome_process_singleton.h"
6
7 #include <utility>
8
9 namespace {
10
11 ChromeProcessSingleton* g_chrome_process_singleton_ = nullptr;
12
13 }  // namespace
14
15 ChromeProcessSingleton::ChromeProcessSingleton(
16     const base::FilePath& user_data_dir)
17     : startup_lock_(
18           base::BindRepeating(&ChromeProcessSingleton::NotificationCallback,
19                               base::Unretained(this))),
20       process_singleton_(user_data_dir,
21                          startup_lock_.AsNotificationCallback()) {}
22
23 ChromeProcessSingleton::~ChromeProcessSingleton() = default;
24
25 ProcessSingleton::NotifyResult
26     ChromeProcessSingleton::NotifyOtherProcessOrCreate() {
27   CHECK(!is_singleton_instance_);
28   ProcessSingleton::NotifyResult result =
29       process_singleton_.NotifyOtherProcessOrCreate();
30   if (result == ProcessSingleton::PROCESS_NONE) {
31     is_singleton_instance_ = true;
32   }
33   return result;
34 }
35
36 void ChromeProcessSingleton::StartWatching() {
37   process_singleton_.StartWatching();
38 }
39
40 void ChromeProcessSingleton::Cleanup() {
41   if (is_singleton_instance_) {
42     process_singleton_.Cleanup();
43   }
44 }
45
46 void ChromeProcessSingleton::Unlock(
47     const ProcessSingleton::NotificationCallback& notification_callback) {
48   notification_callback_ = notification_callback;
49   startup_lock_.Unlock();
50 }
51
52 // static
53 void ChromeProcessSingleton::CreateInstance(
54     const base::FilePath& user_data_dir) {
55   DCHECK(!g_chrome_process_singleton_);
56   DCHECK(!user_data_dir.empty());
57   g_chrome_process_singleton_ = new ChromeProcessSingleton(user_data_dir);
58 }
59
60 // static
61 void ChromeProcessSingleton::DeleteInstance() {
62   if (g_chrome_process_singleton_) {
63     delete g_chrome_process_singleton_;
64     g_chrome_process_singleton_ = nullptr;
65   }
66 }
67
68 // static
69 ChromeProcessSingleton* ChromeProcessSingleton::GetInstance() {
70   CHECK(g_chrome_process_singleton_);
71   return g_chrome_process_singleton_;
72 }
73
74 // static
75 bool ChromeProcessSingleton::IsSingletonInstance() {
76   return g_chrome_process_singleton_ &&
77          g_chrome_process_singleton_->is_singleton_instance_;
78 }
79
80 bool ChromeProcessSingleton::NotificationCallback(
81     const base::CommandLine& command_line,
82     const base::FilePath& current_directory) {
83   DCHECK(notification_callback_);
84   return notification_callback_.Run(command_line, current_directory);
85 }