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

Side by Side Diff: chrome/browser/ui/webui/chromeos/drive_internals_ui.cc

Issue 10808116: gdata: Add authentication status section to chrome:drive-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/chromeos/drive_internals_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
6 6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "chrome/browser/chromeos/gdata/gdata_auth_service.h"
10 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
11 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
7 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 13 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
9 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
16 #include "content/public/browser/web_ui_message_handler.h"
11 #include "grit/browser_resources.h" 17 #include "grit/browser_resources.h"
12 18
13 namespace chromeos { 19 namespace chromeos {
14 20
21 namespace {
22
23 // Class to handle messages from chrome://drive-internals.
24 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
25 public:
26 DriveInternalsWebUIHandler()
27 : weak_ptr_factory_(this) {
28 }
29
30 virtual ~DriveInternalsWebUIHandler() {
31 }
32
33 private:
34 // WebUIMessageHandler override.
35 virtual void RegisterMessages() OVERRIDE {
36 web_ui()->RegisterMessageCallback(
37 "pageLoaded",
38 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded,
39 weak_ptr_factory_.GetWeakPtr()));
40 }
41
42 // Called when the page is first loaded.
43 void OnPageLoaded(const base::ListValue* args) {
44 Profile* profile = Profile::FromWebUI(web_ui());
45 gdata::GDataSystemService* system_service =
46 gdata::GDataSystemServiceFactory::GetForProfile(profile);
47 // |system_service| may be NULL in the guest/incognito mode.
achuithb 2012/07/25 00:37:00 You may want to test this. Some chrome:// pages au
48 if (!system_service)
49 return;
50
51 gdata::DocumentsServiceInterface* documents_service =
52 system_service->docs_service();
53 DCHECK(documents_service);
54
55 // Update the auth status section.
56 DictionaryValue auth_status;
57 auth_status.SetBoolean("has-fresh-token",
58 documents_service->IsFullyAuthenticated());
59 auth_status.SetBoolean("has-auth-token",
60 documents_service->IsPartiallyAuthenticated());
61 web_ui()->CallJavascriptFunction("UpdateAuthStatus", auth_status);
62 }
63
64 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
65 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
66 };
67
68 } // namespace
69
15 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) 70 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
16 : WebUIController(web_ui) { 71 : WebUIController(web_ui) {
72 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler());
73
17 ChromeWebUIDataSource* source = 74 ChromeWebUIDataSource* source =
18 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); 75 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
19 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 76 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
20 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); 77 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);
21 78
22 Profile* profile = Profile::FromWebUI(web_ui); 79 Profile* profile = Profile::FromWebUI(web_ui);
23 ChromeURLDataManager::AddDataSource(profile, source); 80 ChromeURLDataManager::AddDataSource(profile, source);
24 } 81 }
25 82
26 } // namespace chromeos 83 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698