OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/remoting/remoting_setup_flow.h" | 5 #include "chrome/browser/remoting/remoting_setup_flow.h" |
6 | 6 |
7 #include "app/gfx/font_util.h" | 7 #include "app/gfx/font_util.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 // A callback to notify the delegate that the dialog closed. | 63 // A callback to notify the delegate that the dialog closed. |
64 void RemotingSetupFlow::OnDialogClosed(const std::string& json_retval) { | 64 void RemotingSetupFlow::OnDialogClosed(const std::string& json_retval) { |
65 // If we are fetching the token then cancel the request. | 65 // If we are fetching the token then cancel the request. |
66 if (authenticator_.get()) | 66 if (authenticator_.get()) |
67 authenticator_->CancelRequest(); | 67 authenticator_->CancelRequest(); |
68 delete this; | 68 delete this; |
69 } | 69 } |
70 | 70 |
71 // static | |
72 void RemotingSetupFlow::GetArgsForGaiaLogin(DictionaryValue* args) { | |
73 args->SetString("iframeToShow", "login"); | |
74 args->SetString("user", ""); | |
75 args->SetInteger("error", 0); | |
76 args->SetBoolean("editable_user", true); | |
77 } | |
78 | |
79 void RemotingSetupFlow::GetDOMMessageHandlers( | 71 void RemotingSetupFlow::GetDOMMessageHandlers( |
80 std::vector<DOMMessageHandler*>* handlers) const { | 72 std::vector<DOMMessageHandler*>* handlers) const { |
81 // Create the message handler only after we are asked. | 73 // Create the message handler only after we are asked. |
82 handlers->push_back(message_handler_); | 74 handlers->push_back(message_handler_); |
83 } | 75 } |
84 | 76 |
85 void RemotingSetupFlow::Focus() { | 77 void RemotingSetupFlow::Focus() { |
86 // TODO(pranavk): implement this method. | 78 // TODO(pranavk): implement this method. |
87 NOTIMPLEMENTED(); | 79 NOTIMPLEMENTED(); |
88 } | 80 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 ChromeThread::UI, | 153 ChromeThread::UI, |
162 FROM_HERE, | 154 FROM_HERE, |
163 NewRunnableMethod(this, &RemotingSetupFlow::OnProcessLaunched)); | 155 NewRunnableMethod(this, &RemotingSetupFlow::OnProcessLaunched)); |
164 return; | 156 return; |
165 } | 157 } |
166 | 158 |
167 DCHECK(process_control_->is_connected()); | 159 DCHECK(process_control_->is_connected()); |
168 process_control_->EnableRemotingWithTokens(login_, remoting_token_, | 160 process_control_->EnableRemotingWithTokens(login_, remoting_token_, |
169 sync_token_); | 161 sync_token_); |
170 message_handler_->ShowSetupDone(); | 162 message_handler_->ShowSetupDone(); |
| 163 |
| 164 // Save the preference that we have completed the setup of remoting. |
| 165 profile_->GetPrefs()->SetBoolean(prefs::kRemotingHasSetupCompleted, true); |
171 } | 166 } |
172 | 167 |
173 // static | 168 // static |
174 RemotingSetupFlow* RemotingSetupFlow::Run(Profile* profile) { | 169 RemotingSetupFlow* RemotingSetupFlow::Run(Profile* profile) { |
175 // Set the arguments for showing the gaia login page. | 170 // Set the arguments for showing the gaia login page. |
176 DictionaryValue args; | 171 DictionaryValue args; |
177 GetArgsForGaiaLogin(&args); | 172 args.SetString("iframeToShow", "login"); |
| 173 args.SetString("user", ""); |
| 174 args.SetInteger("error", 0); |
| 175 args.SetBoolean("editable_user", true); |
| 176 |
| 177 if (profile->GetPrefs()->GetBoolean(prefs::kRemotingHasSetupCompleted)) { |
| 178 args.SetString("iframeToShow", "done"); |
| 179 } |
| 180 |
178 std::string json_args; | 181 std::string json_args; |
179 base::JSONWriter::Write(&args, false, &json_args); | 182 base::JSONWriter::Write(&args, false, &json_args); |
180 | 183 |
181 RemotingSetupFlow* flow = new RemotingSetupFlow(json_args, profile); | 184 RemotingSetupFlow* flow = new RemotingSetupFlow(json_args, profile); |
182 Browser* b = BrowserList::GetLastActive(); | 185 Browser* b = BrowserList::GetLastActive(); |
183 if (b) { | 186 if (b) { |
184 b->BrowserShowHtmlDialog(flow, NULL); | 187 b->BrowserShowHtmlDialog(flow, NULL); |
185 } else { | 188 } else { |
186 delete flow; | 189 delete flow; |
187 return NULL; | 190 return NULL; |
188 } | 191 } |
189 return flow; | 192 return flow; |
190 } | 193 } |
191 | 194 |
192 // Global function to start the remoting setup dialog. | 195 // Global function to start the remoting setup dialog. |
193 void OpenRemotingSetupDialog(Profile* profile) { | 196 void OpenRemotingSetupDialog(Profile* profile) { |
194 RemotingSetupFlow::Run(profile->GetOriginalProfile()); | 197 RemotingSetupFlow::Run(profile->GetOriginalProfile()); |
195 } | 198 } |
196 | 199 |
197 // TODO(hclam): Need to refcount RemotingSetupFlow. I need to lifetime of | 200 // TODO(hclam): Need to refcount RemotingSetupFlow. I need to fix |
198 // objects are all correct. | 201 // lifetime of objects. |
199 DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupFlow); | 202 DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupFlow); |
200 DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupMessageHandler); | 203 DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupMessageHandler); |
OLD | NEW |