Skip to content

Commit

Permalink
Third try at landing gRPC refactoring. Previous iteration failed on o…
Browse files Browse the repository at this point in the history
…pt builds because it did work inside a DCHECK().

Revert "Revert of Revert "Revert of Moving gRPC support interfaces out of cronet and into a new component. (patchset … (patchset #5 id:100001 of https://codereview.chromium.org/2470923002/ )"

This reverts commit f42bc4c.

TBR=blundell@chromium.org
BUG=650462

Review-Url: https://codereview.chromium.org/2492703002
Cr-Commit-Position: refs/heads/master@{#431366}
  • Loading branch information
gcasto authored and Commit bot committed Nov 10, 2016
1 parent bc0614e commit 67ace93
Show file tree
Hide file tree
Showing 30 changed files with 1,124 additions and 813 deletions.
1 change: 1 addition & 0 deletions components/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test("components_unittests") {
"//components/gcm_driver:unit_tests",
"//components/gcm_driver/crypto:unit_tests",
"//components/google/core/browser:unit_tests",
"//components/grpc_support/test:unit_tests",
"//components/history/core/browser:unit_tests",
"//components/history/core/common:unit_tests",
"//components/image_fetcher:unit_tests",
Expand Down
1 change: 1 addition & 0 deletions components/cronet/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+components/grpc_support",
"+components/metrics",
"+components/prefs",
"+net",
Expand Down
19 changes: 11 additions & 8 deletions components/cronet/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import("//build/config/mac/symbols.gni")
import("//build/mac/tweak_info_plist.gni")
import("//build/util/process_version.gni")
import("//build/util/version.gni")
import("//components/grpc_support/include/headers.gni")
import("//testing/test.gni")
import("//url/features.gni")

Expand All @@ -33,6 +34,7 @@ source_set("cronet_sources") {
deps = [
":cronet_version_header",
"//base:base",
"//components/grpc_support",
"//components/metrics:metrics",
"//components/metrics/proto:proto",
"//components/prefs:prefs",
Expand All @@ -51,14 +53,12 @@ source_set("cronet_sources") {
"../url_request_context_config.h",
"Cronet.h",
"Cronet.mm",
"cronet_bidirectional_stream.cc",
"cronet_bidirectional_stream.h",
"cronet_c_for_grpc.cc",
"cronet_c_for_grpc.h",
"cronet_environment.cc",
"cronet_environment.h",
]

include_dirs = [ "//components/grpc_support/include" ]

if (!use_platform_icu_alternatives) {
deps += [ "//base:i18n" ]
}
Expand Down Expand Up @@ -147,14 +147,17 @@ ios_framework_bundle("cronet_framework") {

libs = [ "UIKit.Framework" ]

public_headers = [
"Cronet.h",
"cronet_c_for_grpc.h",
include_dirs = [ "//components/grpc_support/include" ]

public_deps = [
"//components/grpc_support",
]

public_headers = [ "Cronet.h" ]
public_headers += grpc_public_headers

sources = [
"Cronet.h",
"cronet_c_for_grpc.h",
]

configs -= [ "//build/config/compiler:default_symbols" ]
Expand Down
10 changes: 6 additions & 4 deletions components/cronet/ios/Cronet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

#import <Foundation/Foundation.h>

#include "cronet_c_for_grpc.h"
#include "bidirectional_stream_c.h"

// A block, that takes a request, and returns YES if the request should
// be handled.
typedef BOOL (^RequestFilterBlock)(NSURLRequest* request);

// Interface for installing Cronet.
CRONET_EXPORT
// TODO(gcasto): Should this macro be separate from the one defined in
// bidirectional_stream_c.h?
GRPC_SUPPORT_EXPORT
@interface Cronet : NSObject

// Sets whether HTTP/2 should be supported by CronetEngine. This method only has
Expand Down Expand Up @@ -89,7 +91,7 @@ CRONET_EXPORT
+ (NSString*)getUserAgent;

// Get a pointer to global instance of cronet_engine for GRPC C API.
+ (cronet_engine*)getGlobalEngine;
+ (stream_engine*)getGlobalEngine;

// Returns differences in metrics collected by Cronet since the last call to
// getGlobalMetricsDeltas, serialized as a [protobuf]
Expand All @@ -101,7 +103,7 @@ CRONET_EXPORT
+ (NSData*)getGlobalMetricsDeltas;

// Sets Host Resolver Rules for testing.
// This method only has any effect before |start| is called.
// This method must be called after |start| has been called.
+ (void)setHostResolverRulesForTesting:(NSString*)hostResolverRulesForTesting;

// Enables TestCertVerifier which accepts all certificates for testing.
Expand Down
17 changes: 8 additions & 9 deletions components/cronet/ios/Cronet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate;
NSURLCache* gPreservedSharedURLCache = nil;
BOOL gEnableTestCertVerifierForTesting = FALSE;
NSString* gHostResolverRulesForTesting = @"";

// CertVerifier, which allows any certificates for testing.
class TestCertVerifier : public net::CertVerifier {
Expand Down Expand Up @@ -106,8 +105,6 @@ @implementation Cronet

+ (void)configureCronetEnvironmentForTesting:
(cronet::CronetEnvironment*)cronetEnvironment {
cronetEnvironment->set_host_resolver_rules(
[gHostResolverRulesForTesting UTF8String]);
if (gEnableTestCertVerifierForTesting) {
std::unique_ptr<TestCertVerifier> test_cert_verifier =
base::MakeUnique<TestCertVerifier>();
Expand Down Expand Up @@ -254,11 +251,11 @@ + (NSString*)getUserAgent {
encoding:[NSString defaultCStringEncoding]];
}

+ (cronet_engine*)getGlobalEngine {
+ (stream_engine*)getGlobalEngine {
DCHECK(gChromeNet.Get().get());
if (gChromeNet.Get().get()) {
static cronet_engine engine;
engine.obj = gChromeNet.Get().get();
static stream_engine engine;
engine.obj = gChromeNet.Get()->GetURLRequestContextGetter();
return &engine;
}
return nil;
Expand All @@ -277,13 +274,15 @@ + (void)enableTestCertVerifierForTesting {
}

+ (void)setHostResolverRulesForTesting:(NSString*)hostResolverRulesForTesting {
gHostResolverRulesForTesting = hostResolverRulesForTesting;
DCHECK(gChromeNet.Get().get());
gChromeNet.Get()->SetHostResolverRules(
base::SysNSStringToUTF8(hostResolverRulesForTesting));
}

// This is a non-public dummy method that prevents the linker from stripping out
// the otherwise non-referenced methods from 'cronet_bidirectional_stream.cc'.
// the otherwise non-referenced methods from 'bidirectional_stream.cc'.
+ (void)preventStrippingCronetBidirectionalStream {
cronet_bidirectional_stream_create(NULL, 0, 0);
bidirectional_stream_create(NULL, 0, 0);
}

@end
Loading

0 comments on commit 67ace93

Please sign in to comment.