diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-23 22:01:25 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-23 22:01:25 +0000 |
commit | 52ded45f70f0defc422d0fcf2b1cd873be839a69 (patch) | |
tree | 941775d84d7f4cf93b60a11324dc955022323a16 /chrome/browser/search_engines | |
parent | 36e8db95f83d177c765a4401ad86df822b81efc2 (diff) | |
download | chromium_src-52ded45f70f0defc422d0fcf2b1cd873be839a69.zip chromium_src-52ded45f70f0defc422d0fcf2b1cd873be839a69.tar.gz chromium_src-52ded45f70f0defc422d0fcf2b1cd873be839a69.tar.bz2 |
Skeleton of sync handler on the I/O thread for GetSearchProviderInstallState.
BUG=38475
TEST=Not fully testable yet (but the test is
unit_test --gtest_filter=SearchProviderTest.TestIsSearchProviderInstalled
Review URL: http://codereview.chromium.org/3117034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57114 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines')
-rw-r--r-- | chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc | 90 | ||||
-rw-r--r-- | chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h | 56 |
2 files changed, 146 insertions, 0 deletions
diff --git a/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc new file mode 100644 index 0000000..87803ba --- /dev/null +++ b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc @@ -0,0 +1,90 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h" + +#include "base/logging.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/resource_message_filter.h" +#include "chrome/common/render_messages.h" +#include "ipc/ipc_message.h" +#include "googleurl/src/gurl.h" + +SearchProviderInstallStateDispatcherHost:: +SearchProviderInstallStateDispatcherHost( + ResourceMessageFilter* ipc_sender, + Profile* profile) + : ipc_sender_(ipc_sender), + is_off_the_record_(profile->IsOffTheRecord()) { + // This is initialized by ResourceMessageFilter. Do not add any non-trivial + // initialization here. Instead do it lazily when required. + DCHECK(ipc_sender); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); +} + +SearchProviderInstallStateDispatcherHost:: +~SearchProviderInstallStateDispatcherHost() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); +} + +void SearchProviderInstallStateDispatcherHost::Send(IPC::Message* message) { + ipc_sender_->Send(message); +} + +bool SearchProviderInstallStateDispatcherHost::OnMessageReceived( + const IPC::Message& message, + bool* message_was_ok) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(SearchProviderInstallStateDispatcherHost, message, + *message_was_ok) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetSearchProviderInstallState, + OnMsgGetSearchProviderInstallState) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +ViewHostMsg_GetSearchProviderInstallState_Params +SearchProviderInstallStateDispatcherHost::GetSearchProviderInstallState( + const GURL& page_location, + const GURL& requested_host) { + GURL requested_origin = requested_host.GetOrigin(); + + // Do the security check before any others to avoid information leaks. + if (page_location.GetOrigin() != requested_origin) + return ViewHostMsg_GetSearchProviderInstallState_Params::Denied(); + + // In incognito mode, no search information is exposed. (This check must be + // done after the security check or else a web site can detect that the + // user is in incognito mode just by doing a cross origin request.) + if (is_off_the_record_) + return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled(); + + // TODO(levin): Real logic goes here. + return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled(); +} + +void +SearchProviderInstallStateDispatcherHost::OnMsgGetSearchProviderInstallState( + const GURL& page_location, + const GURL& requested_host, + IPC::Message* reply_msg) { + ViewHostMsg_GetSearchProviderInstallState_Params install_state = + GetSearchProviderInstallState(page_location, requested_host); + ReplyWithProviderInstallState(reply_msg, install_state); +} + +void SearchProviderInstallStateDispatcherHost::ReplyWithProviderInstallState( + IPC::Message* reply_msg, + ViewHostMsg_GetSearchProviderInstallState_Params install_state) { + DCHECK(reply_msg); + + ViewHostMsg_GetSearchProviderInstallState::WriteReplyParams( + reply_msg, + install_state); + Send(reply_msg); +} diff --git a/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h new file mode 100644 index 0000000..d7de57f --- /dev/null +++ b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h @@ -0,0 +1,56 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_STATE_DISPATCHER_HOST_H_ +#define CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_STATE_DISPATCHER_HOST_H_ + +#include "base/basictypes.h" + +namespace IPC { +class Message; +} + +class GURL; +class Profile; +class ResourceMessageFilter; +struct ViewHostMsg_GetSearchProviderInstallState_Params; + +// Handles messages regarding search provider install state on the I/O thread. +class SearchProviderInstallStateDispatcherHost { + public: + // Unlike the other methods, the constructor is called on the UI thread. + SearchProviderInstallStateDispatcherHost(ResourceMessageFilter* ipc_sender, + Profile* profile); + ~SearchProviderInstallStateDispatcherHost(); + + // Send a message to the renderer process. + void Send(IPC::Message* message); + + // Called to possibly handle the incoming IPC message. Returns true if + // handled. + bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); + + private: + // Figures out the install state for the search provider. + ViewHostMsg_GetSearchProviderInstallState_Params + GetSearchProviderInstallState(const GURL& page_location, + const GURL& requested_host); + + // Starts handling the message requesting the search provider install state. + void OnMsgGetSearchProviderInstallState(const GURL& page_location, + const GURL& requested_host, + IPC::Message* reply_msg); + + // Sends the reply message about the search provider install state. + void ReplyWithProviderInstallState( + IPC::Message* reply_msg, + ViewHostMsg_GetSearchProviderInstallState_Params install_state); + + ResourceMessageFilter* ipc_sender_; + const bool is_off_the_record_; + + DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallStateDispatcherHost); +}; + +#endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_STATE_DISPATCHER_HOST_H_ |