Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include "chrome/browser/extensions/api/messaging/arc_opt_in_host.h" | |
| 6 | |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/json/json_writer.h" | |
| 9 #include "base/values.h" | |
| 10 | |
| 11 namespace { | |
| 12 const char kAction[] = "action"; | |
| 13 const char kActionFetchAuthCode[] = "fetchAuthCode"; | |
| 14 const char kActionCloseUI[] = "closeUI"; | |
| 15 } | |
|
xiyuan
2016/02/11 17:57:20
nit: } // namespace
khmel
2016/02/12 02:45:23
Done.
| |
| 16 | |
| 17 // static | |
| 18 const char ArcOptInHost::kHostName[] = "com.google.arc_opt_in"; | |
| 19 | |
| 20 // static | |
| 21 const char* const ArcOptInHost::kHostOrigin[] = { | |
| 22 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/" | |
| 23 }; | |
| 24 | |
| 25 ArcOptInHost::ArcOptInHost() { | |
| 26 arc::ArcAuthService::Get()->AddObserver(this); | |
| 27 } | |
| 28 | |
| 29 ArcOptInHost::~ArcOptInHost() { | |
| 30 arc::ArcAuthService::Get()->RemoveObserver(this); | |
| 31 } | |
| 32 | |
| 33 void ArcOptInHost::Start(Client* client) { | |
| 34 DCHECK(!client_); | |
| 35 client_ = client; | |
| 36 } | |
| 37 | |
| 38 void ArcOptInHost::OnOptInUINeedToClose() { | |
| 39 if (!client_) | |
| 40 return; | |
| 41 | |
| 42 base::DictionaryValue response; | |
| 43 response.SetString(kAction, kActionCloseUI); | |
| 44 std::string response_string; | |
| 45 base::JSONWriter::Write(response, &response_string); | |
| 46 client_->PostMessageFromNativeHost(response_string); | |
| 47 } | |
| 48 | |
| 49 void ArcOptInHost::OnMessage(const std::string& request_string) { | |
| 50 scoped_ptr<base::Value> request_value = | |
| 51 base::JSONReader::Read(request_string); | |
| 52 scoped_ptr<base::DictionaryValue> request( | |
| 53 static_cast<base::DictionaryValue*>(request_value.release())); | |
| 54 if (!request.get()) { | |
| 55 NOTREACHED(); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 std::string action; | |
| 60 if (!request->GetString(kAction, &action)) { | |
| 61 NOTREACHED(); | |
| 62 return; | |
| 63 } | |
| 64 | |
| 65 if (action == kActionFetchAuthCode) { | |
| 66 arc::ArcAuthService::Get()->CheckAuthCode(); | |
| 67 } else { | |
| 68 NOTREACHED(); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 scoped_refptr<base::SingleThreadTaskRunner> ArcOptInHost::task_runner() const { | |
| 73 return base::ThreadTaskRunnerHandle::Get(); | |
| 74 } | |
| OLD | NEW |