Home | History | Annotate | Download | only in frame_host
      1 // Copyright 2014 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 "content/browser/frame_host/navigation_request.h"
      6 
      7 #include "base/logging.h"
      8 #include "content/browser/loader/resource_dispatcher_host_impl.h"
      9 #include "content/common/resource_request_body.h"
     10 #include "content/public/browser/browser_thread.h"
     11 
     12 namespace content {
     13 
     14 namespace {
     15 
     16 // The next available browser-global navigation request ID.
     17 static int64 next_navigation_request_id_ = 0;
     18 
     19 void OnBeginNavigation(const NavigationRequestInfo& info,
     20                        scoped_refptr<ResourceRequestBody> request_body,
     21                        int64 navigation_request_id,
     22                        int64 frame_tree_node_id) {
     23   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
     24   ResourceDispatcherHostImpl::Get()->StartNavigationRequest(
     25       info, request_body, navigation_request_id, frame_tree_node_id);
     26 }
     27 
     28 void CancelNavigationRequest(int64 navigation_request_id,
     29                              int64 frame_tree_node_id) {
     30   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
     31   ResourceDispatcherHostImpl::Get()->CancelNavigationRequest(
     32       navigation_request_id, frame_tree_node_id);
     33 }
     34 
     35 }  // namespace
     36 
     37 NavigationRequest::NavigationRequest(const NavigationRequestInfo& info,
     38                                      int64 frame_tree_node_id)
     39   : navigation_request_id_(++next_navigation_request_id_),
     40     info_(info),
     41     frame_tree_node_id_(frame_tree_node_id) {
     42 }
     43 
     44 NavigationRequest::~NavigationRequest() {
     45 }
     46 
     47 void NavigationRequest::BeginNavigation(
     48     scoped_refptr<ResourceRequestBody> request_body) {
     49   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     50   BrowserThread::PostTask(
     51       BrowserThread::IO,
     52       FROM_HERE,
     53       base::Bind(&OnBeginNavigation,
     54                  info_,
     55                  request_body,
     56                  navigation_request_id_,
     57                  frame_tree_node_id_));
     58 }
     59 
     60 void NavigationRequest::CancelNavigation() {
     61   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     62   BrowserThread::PostTask(
     63       BrowserThread::IO,
     64       FROM_HERE,
     65       base::Bind(&CancelNavigationRequest,
     66                  navigation_request_id_, frame_tree_node_id_));
     67 }
     68 
     69 }  // namespace content
     70