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

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: 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 // Class to handle messages from chrome://drive-internals.
22 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
achuithb 2012/07/24 23:53:20 Why not put this in anonymous scope?
satorux1 2012/07/25 00:32:23 Done.
23 public:
24 DriveInternalsWebUIHandler()
25 : weak_ptr_factory_(this) {
26 }
27
28 ~DriveInternalsWebUIHandler() {
achuithb 2012/07/24 23:53:20 Should this be virtual?
satorux1 2012/07/25 00:32:23 Done.
29 }
30
31 // WebUIMessageHandler override.
32 virtual void RegisterMessages() OVERRIDE {
achuithb 2012/07/24 23:53:20 This can be private, I believe.
satorux1 2012/07/25 00:32:23 Done.
33 web_ui()->RegisterMessageCallback(
34 "pageLoaded",
35 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded,
36 weak_ptr_factory_.GetWeakPtr()));
37 }
38
39 private:
40 // Called when the page is first loaded.
41 void OnPageLoaded(const base::ListValue* args) {
42 Profile* profile = Profile::FromWebUI(web_ui());
43 gdata::GDataSystemService* system_service =
44 gdata::GDataSystemServiceFactory::GetForProfile(profile);
45 DCHECK(system_service);
achuithb 2012/07/24 23:53:20 Is it possible to launch this page in guest/incogn
satorux1 2012/07/25 00:32:23 Good point. Will |system_service| be NULL in the g
46 gdata::DocumentsServiceInterface* documents_service =
47 system_service->docs_service();
48 DCHECK(documents_service);
49
50 // Update the auth status section.
51 DictionaryValue auth_status;
52 auth_status.SetBoolean("has-fresh-token",
53 documents_service->IsFullyAuthenticated());
54 auth_status.SetBoolean("has-auth-token",
55 documents_service->IsPartiallyAuthenticated());
56 web_ui()->CallJavascriptFunction("UpdateAuthStatus", auth_status);
57 }
58
59 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
60 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
61 };
62
15 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) 63 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
16 : WebUIController(web_ui) { 64 : WebUIController(web_ui) {
65 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler());
66
17 ChromeWebUIDataSource* source = 67 ChromeWebUIDataSource* source =
18 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); 68 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
19 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 69 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
20 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); 70 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);
21 71
22 Profile* profile = Profile::FromWebUI(web_ui); 72 Profile* profile = Profile::FromWebUI(web_ui);
23 ChromeURLDataManager::AddDataSource(profile, source); 73 ChromeURLDataManager::AddDataSource(profile, source);
24 } 74 }
25 75
26 } // namespace chromeos 76 } // 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