Commit 499acc80 authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

Revert "DownloadTaskImpl implementation for //ios/web Download API."

This reverts commit cef83520.

Reason for revert: DownloadTaskImplTest.* tests fail on iOS 11 devices, both iPhone and iPad.

Original change's description:
> DownloadTaskImpl implementation for //ios/web Download API.
> 
> This CL implements DownloadTask public interface.
> 
> DownloadControllerImpl CL: crrev.com/c/758525
> Design doc: http://go/ios-web-download-api
> 
> Bug: 780646
> Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
> Change-Id: I2c508e77f3e529223499d6f2791b28011589fe90
> Reviewed-on: https://chromium-review.googlesource.com/758506
> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
> Reviewed-by: Gregory Chatzinoff <gchatz@chromium.org>
> Commit-Queue: Eugene But <eugenebut@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#517176}

TBR=sdefresne@chromium.org,eugenebut@chromium.org,gchatz@chromium.org

Change-Id: I14f0c37aa92330b0a665bf59bb665f010ee1209d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 780646
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/776067Reviewed-by: default avatarYuke Liao <liaoyuke@chromium.org>
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517225}
parent 5c3c4ac8
......@@ -40,7 +40,6 @@ source_set("web") {
":navigation_resources",
":resources",
"//base",
"//ios/web/download",
"//ios/web/interstitials",
"//ios/web/navigation",
"//ios/web/net",
......@@ -167,7 +166,6 @@ test("ios_web_unittests") {
":ios_web_web_state_unittests",
":ios_web_webui_unittests",
"//ios/testing:http_server_bundle_data",
"//ios/web/download:download_unittests",
]
assert_no_deps = ios_assert_no_deps
......
# Copyright 2017 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.
import("//ios/build/config.gni")
source_set("download") {
deps = [
"//base",
"//ios/web/net/cookies",
"//ios/web/public",
"//ios/web/public/download",
"//ios/web/web_state:error_translation_util",
]
sources = [
"download_task_impl.h",
"download_task_impl.mm",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("download_unittests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
deps = [
"//base",
"//ios/testing:ios_test_support",
"//ios/testing:ocmock_support",
"//ios/web/download",
"//ios/web/net/cookies",
"//ios/web/public/download",
"//ios/web/public/test",
"//ios/web/public/test/fakes",
"//ios/web/test/fakes",
"//net",
"//testing/gmock",
"//testing/gtest",
]
sources = [
"download_task_impl_unittest.mm",
]
}
eugenebut@chromium.org
gchatz@chromium.org
# TEAM: ios-directory-owners@chromium.org
# OS: iOS
// Copyright 2017 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 IOS_WEB_DOWNLOAD_DOWNLOAD_TASK_IMPL_H_
#define IOS_WEB_DOWNLOAD_DOWNLOAD_TASK_IMPL_H_
#include <string>
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#import "ios/web/public/download/download_task.h"
#include "url/gurl.h"
@class NSURLSession;
namespace net {
class URLFetcherResponseWriter;
}
namespace web {
class DownloadTaskObserver;
class WebState;
// Implements DownloadTask interface. Uses background NSURLSession as
// implementation.
class DownloadTaskImpl : public DownloadTask {
public:
class Delegate {
public:
// Called when download task is about to be destroyed. Delegate should
// remove all references to the given DownloadTask and stop using it.
virtual void OnTaskDestroyed(DownloadTaskImpl* task) = 0;
// Creates background NSURLSession with given |identifier|, |delegate| and
// |delegate_queue|.
virtual NSURLSession* CreateSession(NSString* identifier,
id<NSURLSessionDataDelegate> delegate,
NSOperationQueue* delegate_queue) = 0;
virtual ~Delegate() = default;
};
// Constructs a new DownloadTaskImpl objects. |web_state|, |identifier| and
// |delegate| must be valid.
DownloadTaskImpl(const WebState* web_state,
const GURL& original_url,
const std::string& content_disposition,
int64_t total_bytes,
const std::string& mime_type,
NSString* identifier,
Delegate* delegate);
// Stops the download operation and clears the delegate.
void ShutDown();
// DownloadTask overrides:
void Start(std::unique_ptr<net::URLFetcherResponseWriter> writer) override;
net::URLFetcherResponseWriter* GetResponseWriter() const override;
NSString* GetIndentifier() const override;
const GURL& GetOriginalUrl() const override;
bool IsDone() const override;
int GetErrorCode() const override;
int64_t GetTotalBytes() const override;
int GetPercentComplete() const override;
std::string GetContentDisposition() const override;
std::string GetMimeType() const override;
base::string16 GetSuggestedFilename() const override;
void AddObserver(DownloadTaskObserver* observer) override;
void RemoveObserver(DownloadTaskObserver* observer) override;
~DownloadTaskImpl() override;
private:
// Creates background NSURLSession with given |identifier|.
NSURLSession* CreateSession(NSString* identifier);
// Asynchronously returns cookies for WebState associated with this task (on
// iOS 10 and earlier, the array is always empty as it is not possible to
// access the cookies). Must be called on UI thread. The callback will be
// invoked on the UI thread.
void GetCookies(base::Callback<void(NSArray<NSHTTPCookie*>*)> callback);
// Asynchronously returns cookies for WebState associated with this task. Must
// be called on UI thread. The callback will be invoked on the UI thread.
void GetWKCookies(base::Callback<void(NSArray<NSHTTPCookie*>*)> callback)
API_AVAILABLE(ios(11.0));
// Starts the download with given cookies.
void StartWithCookies(NSArray<NSHTTPCookie*>* cookies);
// Called when download task was updated.
void OnDownloadUpdated();
// Called when download was completed and the data writing was finished.
void OnDownloadFinished(int error_code);
// A list of observers. Weak references.
base::ObserverList<DownloadTaskObserver, true> observers_;
// Back up corresponding public methods of DownloadTask interface.
std::unique_ptr<net::URLFetcherResponseWriter> writer_;
GURL original_url_;
bool is_done_ = false;
int error_code_ = 0;
int64_t total_bytes_ = -1;
int percent_complete_ = -1;
std::string content_disposition_;
std::string mime_type_;
const WebState* web_state_ = nullptr;
Delegate* delegate_ = nullptr;
NSURLSession* session_ = nil;
NSURLSessionTask* session_task_ = nil;
base::WeakPtrFactory<DownloadTaskImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DownloadTaskImpl);
};
} // namespace web
#endif // IOS_WEB_DOWNLOAD_DOWNLOAD_TASK_IMPL_H_
This diff is collapsed.
This diff is collapsed.
......@@ -17,8 +17,6 @@ source_set("fakes") {
sources = [
"crw_fake_back_forward_list.h",
"crw_fake_back_forward_list.mm",
"crw_fake_nsurl_session_task.h",
"crw_fake_nsurl_session_task.mm",
"fake_navigation_manager_delegate.h",
"fake_navigation_manager_delegate.mm",
]
......
// Copyright 2017 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 IOS_WEB_TEST_FAKES_CRW_FAKE_NSURL_SESSION_TASK_H_
#define IOS_WEB_TEST_FAKES_CRW_FAKE_NSURL_SESSION_TASK_H_
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
// Fake NSURLSessionDataTask class which can be used for testing. |cancel| and
// |resume| methods only change the |state| of this task without actually
// starting or stopping the download.
@interface CRWFakeNSURLSessionTask : NSURLSessionDataTask
// Redefined NSURLSessionTask properties as readwrite.
@property(nonatomic) int64_t countOfBytesReceived;
@property(nonatomic) int64_t countOfBytesExpectedToReceive;
@property(nonatomic) NSURLSessionTaskState state;
- (nullable instancetype)initWithURL:(NSURL*)URL NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END
#endif // IOS_WEB_TEST_FAKES_CRW_FAKE_NSURL_SESSION_TASK_H_
// Copyright 2017 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.
#import "ios/web/test/fakes/crw_fake_nsurl_session_task.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CRWFakeNSURLSessionTask ()
// NSURLSessionTask properties.
@property(nullable, readonly, copy) NSURLRequest* originalRequest;
@property(nullable, readonly, copy) NSURLRequest* currentRequest;
@end
@implementation CRWFakeNSURLSessionTask
@synthesize countOfBytesReceived = _countOfBytesReceived;
@synthesize countOfBytesExpectedToReceive = _countOfBytesExpectedToReceive;
@synthesize state = _state;
@synthesize originalRequest = _originalRequest;
@synthesize currentRequest = _currentRequest;
- (instancetype)initWithURL:(NSURL*)URL {
if ((self = [super init])) {
_state = NSURLSessionTaskStateSuspended;
_currentRequest = [NSURLRequest requestWithURL:URL];
_originalRequest = [NSURLRequest requestWithURL:URL];
}
return self;
}
- (void)cancel {
self.state = NSURLSessionTaskStateCanceling;
}
- (void)resume {
self.state = NSURLSessionTaskStateRunning;
}
// A private method, called by -[NSHTTPCookieStorage storeCookies:forTask:].
// Requires stubbing in order to use NSHTTPCookieStorage API.
- (NSString*)_storagePartitionIdentifier {
return nil;
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment